Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <bits/stdc++.h>
- using namespace std;
- int model[3] = {1, 1, 1};
- int getSum(int length, int *arr){
- int sum = 0;
- for(int i = 0; i < length ; i++){
- sum+=arr[i];
- }
- return sum;
- }
- void sortArr(int *arr, int len){
- int array[len];
- for (int i = 0; i < len; i++)
- {
- array[i] = arr[i];
- }
- sort(array, array + len, greater<int>());
- model[0] = array[0];
- model[1] = array[1];
- model[2] = array[2];
- }
- int average(int *loss, int len){
- int avg;
- for (int i = 0; i < len; i++)
- {
- avg += loss[i];
- }
- avg = avg / len;
- return avg;
- }
- void training(int epoch, int *train, int *valid, int *test){
- int loss[epoch];
- int lenTrain = sizeof(train)/sizeof(int);
- int lenValid = sizeof(valid)/sizeof(int);
- int lenTest = sizeof(test)/sizeof(int);
- int tempModel[lenTrain];
- int sumModel = 1000;
- int sumTrain = getSum(lenTrain, train);
- int sumValid = getSum(lenValid, valid);
- int sumTest = getSum(lenTest, test);
- for (int i = 1; i <= epoch; i++)
- {
- loss[i-1] = sumModel * 100 / (epoch * (sumTrain + sumValid + sumTest));
- for(int it = 0; it < lenTest; it++)
- {
- for (int iv = 0; iv < lenValid; iv++)
- {
- for (int iT = 0; iT < lenTrain; iT++)
- {
- tempModel[iT] = (train[iT] + valid[iv]) * test[it];
- }
- }
- }
- sumModel = getSum(lenTrain, tempModel);
- cout << "[Epoch-" << i << "/" << epoch << "] Loss " << loss[i-1] << "%" << endl;
- sortArr(tempModel, lenTrain);
- }
- cout << "[Result] Algorithm CNN - avg Loss " << average(loss, epoch) << "%" << endl;
- cout << "Model Output [" << model[0] << ", " << model[1] << ", " << model[2] << "] " << endl;
- }
- void generateData(int max, int *array){
- for (int i = 0; i < max; i++)
- {
- array[i] = rand() % 100;
- }
- }
- int main() {
- int epoch;
- int trainMax;
- int validMax;
- int testMax;
- string algorithm;
- cin >> algorithm >> epoch;
- cin >> trainMax >> validMax >> testMax;
- int dataTrain[trainMax];
- int dataValid[validMax];
- int dataTest[testMax];
- if (algorithm == "CNN")
- {
- generateData(trainMax, dataTrain);
- generateData(validMax, dataValid);
- generateData(testMax, dataTest);
- training(epoch, dataTrain, dataValid, dataValid);
- } else {
- cout << "Error: Algorithm not found." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement