Державний секретар Сполучених Штатів Марко Рубіо під час візиту до Індії офіційно заявив, що політика Вашингтона щодо надання Україні оборонної підтримки за програмою PURL залишається незмінною, а будь-які затримки в отриманні озброєння мають виключно технічний, а не політичний характер.

Причини логістичних викликів

Ключовою проблемою залишається критичний дефіцит ракет-перехоплювачів, які на сьогодні є найбільш затребуваним ресурсом у світі, що створює конкуренцію між інтересами різних держав та оборонними потребами самих Сполучених Штатів.

  • Величезний попит: кожна країна прагне зміцнити власну протиповітряну оборону за допомогою американських технологій.
  • Баланс ресурсів: США змушені ретельно зважувати зобов’язання перед міжнародними партнерами та вимоги власної національної безпеки.
  • Відсутність політичного тиску: за словами держсекретаря, жодних навмисних директив, спрямованих на послаблення української сторони, не існувало.

#pragma once
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include

// Definitions for the type of data we are processing
typedef std::vector Vector;
typedef std::vector Matrix;

// Helper function to print a vector
void printVector(const Vector& v) {
std::cout << "[ ";
for (double val : v) {
std::cout << val << " ";
}
std::cout << "]" << std::endl;
}

// Helper function to print a matrix
void printMatrix(const Matrix& m) {
std::cout << "Matrix (" << m.size() << "x" << m[0].size() << "):" << std::endl;
for (const auto& row : m) {
printVector(row);
}
}

// — Dataset Generation —
// Generates a dataset for linear regression.
// y = w_true * x + b_true + noise
Matrix generateDataset(int num_samples, double w_true, double b_true, double noise_std) {
std::default_random_engine generator(time(0));
std::normal_distribution dist(0.0, noise_std);

Matrix data(num_samples, Vector(2));
for (int i = 0; i < num_samples; ++i) {
double x = (double)rand() / RAND_MAX * 10.0; // x in [0, 10]
double y = w_true * x + b_true + dist(generator);
data[i][0] = x;
data[i][1] = y;
}
return data;
}

// — Linear Regression Engine —
class LinearRegression {
private:
double w = 0.0;
double b = 0.0;
double learning_rate;
int epochs;

public:
LinearRegression(double lr, int ep) : learning_rate(lr), epochs(ep) {}

// MSE Loss function
double calculateLoss(const Matrix& data) {
double total_error = 0.0;
for (const auto& row : data) {
double prediction = w * row[0] + b;
total_error += std::pow(prediction – row[1], 2);
}
return total_error / data.size();
}

// Gradient Descent
void train(const Matrix& data) {
int n = data.size();
for (int i = 0; i < epochs; ++i) {
double dw = 0.0;
double db = 0.0;

for (const auto& row : data) {
double x = row[0];
double y = row[1];
double error = (w * x + b) – y;
dw += (2.0 / n) * error * x;
db += (2.0 / n) * error;
}

w -= learning_rate * dw;
b -= learning_rate * db;

if (i % 100 == 0) {
std::cout << "Epoch " << i << " | Loss: " << calculateLoss(data) << std::endl;
}
}
}

void getParams() {
std::cout << "Trained Weights: w=" << w << ", b=" << b << std::endl;
}
};

// — Main Execution —
int main() {
// 1. Setup
srand(time(0));
int num_samples = 100;
double w_true = 3.5;
double b_true = 2.0;
double noise = 0.5;

std::cout << "Generating dataset…" << std::endl;
Matrix data = generateDataset(num_samples, w_true, b_true, noise);

// 2. Train Model
LinearRegression model(0.01, 1000);
std::cout << "Training model…" << std::endl;
model.train(data);

// 3. Results
std::cout << "nResults:" << std::endl;
model.getParams();
std::cout << "True values were: w=" << w_true << ", b=" << b_true << std::endl;

return 0;
}
“`

### Explanation of the components:

1. **Dataset Generation (`generateDataset`)**: Creates synthetic data based on the linear equation $y = 3.5x + 2.0$ and adds random Gaussian noise.
2. **Linear Regression Class (`LinearRegression`)**:
* **Loss Function**: Calculates the Mean Squared Error (MSE), which represents how far off our predictions are from the actual data.
* **Gradient Descent (`train`)**: Iteratively updates the weights (`w`) and bias (`b`) by calculating the partial derivatives of the loss function with respect to those parameters.
3. **Execution (`main`)**: Orchestrates the process—data creation, initialization of the model with a learning rate (how fast to change the parameters) and number of epochs (training iterations), and final parameter reporting.

### How to use this:
* **Compile**: Use `g++ -O3 main.cpp -o linreg`.
* **Run**: `./linreg`.
* **Observation**: You will see the loss value decreasing as the model converges toward the true coefficients (3.5 and 2.0).

This code serves as a minimal framework. In a production C++ environment, you would typically use libraries like **Eigen** for matrix operations, as it is much faster and more memory-efficient than `std::vector<std::vector>`.

На переговори в Осло від ЄС і НАТО прибудуть представники команд фон дер Ляєн і Рютте – ЄП Previous post На переговори в Осло від ЄС і НАТО прибудуть представники команд фон дер Ляєн і Рютте – ЄП
Дощі, тумани і до +20° – прогноз погоди на 21-23 жовтня Next post Дощі, тумани і до +20° – прогноз погоди на 21-23 жовтня