#include "daal.h"
#include "service.h"
using namespace std;
using namespace daal;
using namespace daal::algorithms;
using namespace daal::data_management;
string datasetFileName = "../data/batch/mse.csv";
const size_t nIterations = 1000;
const size_t nFeatures = 3;
const float learningRate = 0.5;
const size_t batchSize = 4;
const double accuracyThreshold = 0.0000001;
float initialPoint[nFeatures + 1] = {8, 2, 1, 4};
int main(int argc, char *argv[])
{
FileDataSource<CSVFeatureManager> dataSource(datasetFileName,
DataSource::notAllocateNumericTable,
DataSource::doDictionaryFromContext);
NumericTablePtr data(new HomogenNumericTable<>(nFeatures, 0, NumericTable::doNotAllocate));
NumericTablePtr dependentVariables(new HomogenNumericTable<>(1, 0, NumericTable::doNotAllocate));
NumericTablePtr mergedData(new MergedNumericTable(data, dependentVariables));
dataSource.loadDataBlock(mergedData.get());
size_t nVectors = data->getNumberOfRows();
services::SharedPtr<optimization_solver::mse::Batch<> > mseObjectiveFunction(new optimization_solver::mse::Batch<>(nVectors));
mseObjectiveFunction->input.set(optimization_solver::mse::data, data);
mseObjectiveFunction->input.set(optimization_solver::mse::dependentVariables, dependentVariables);
optimization_solver::sgd::Batch<float, optimization_solver::sgd::momentum> sgdMomentumAlgorithm(mseObjectiveFunction);
sgdMomentumAlgorithm.input.set(optimization_solver::iterative_solver::inputArgument,
NumericTablePtr(new HomogenNumericTable<>(initialPoint, 1, nFeatures + 1)));
sgdMomentumAlgorithm.parameter.learningRateSequence =
NumericTablePtr(new HomogenNumericTable<>(1, 1, NumericTable::doAllocate, learningRate));
sgdMomentumAlgorithm.parameter.nIterations = nIterations;
sgdMomentumAlgorithm.parameter.batchSize = batchSize;
sgdMomentumAlgorithm.parameter.accuracyThreshold = accuracyThreshold;
sgdMomentumAlgorithm.compute();
printNumericTable(sgdMomentumAlgorithm.getResult()->get(optimization_solver::iterative_solver::minimum), "Minimum:");
printNumericTable(sgdMomentumAlgorithm.getResult()->get(optimization_solver::iterative_solver::nIterations), "Number of iterations performed:");
return 0;
}