int main(void){ int i; struct dataSet *data = NULL; double inputs[NUMSAMPLES][NUMINPUTS]; double outputs[NUMSAMPLES][NUMOUTPUTS]; double inputTemp; double outputTemp; for(i=0; i<NUMSAMPLES; i++){ inputTemp = (i * (INPUTRANGE/(NUMSAMPLES-1))) - INPUTRANGE/2; outputTemp = symbolicEq1(inputTemp); inputs[i][0] = inputTemp; outputs[i][0] = outputTemp; } data = initialiseDataSetFromArrays(NUMINPUTS, NUMOUTPUTS, NUMSAMPLES, inputs[0], outputs[0]); saveDataSet(data, "symbolic.data"); freeDataSet(data); return 0; }
int OnlineSession::run(istream *in, ostream *out, bool interactive) { map<string, int> commands; prepareCommands(commands); int res = 0; int count = 0; int cmd; string command; string sarg1, sarg2; int iarg1, iarg2, iarg3, iarg4, iarg5, iarg6, iarg7; double darg1; double *dparg1; TimeSeriesSet *t; clock_t time; res = 0; while (!in->eof()) { if (res != 0) *out << "Command returned with status " << res << "." << endl; if (interactive) { int width = out->width(); *out << "["; out->width(3); *out << count; out->width(width); *out << "] > "; out->flush(); } *in >> command; time = clock(); if (command.size() > 0) { cmd = commands[command]; } if (command.size() <= 0 || in->eof()) { cmd = _EXIT; *out << endl; } if (cmd == 0) { *out << "Unknown command '" << command << "'. Type 'help' for help." << endl; res = 1; count++; continue; } try { res = 0; switch (cmd) { case _EXIT: *out << "Quitting..." << endl; return iarg1; case _HELP: _print_help(out); break; case _LOAD_TSS: *in >> sarg1; *out << "Loading Time Series Set from file '" << sarg1 << "'." << endl; res = loadDataSet(new TimeSeriesSet(sarg1.c_str())); if (res >= 0) { *out << "Dataset successfully loaded. Index: " << res << endl; res = 0; } else { *out << "Failed to load dataset." << endl; } break; case _SAVE_TSS: *in >> iarg1; *in >> sarg2; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Saving Time Series Set " << iarg1 << ":" << t->name << " to file '" << sarg2 << "'." << endl; res = saveDataSet(iarg1, sarg2.c_str()); if (res == 0) *out << "Dataset successfully saved." << endl; break; case _OLOAD_TSS: *in >> sarg1; *in >> iarg1 >> iarg2 >> iarg3; *out << "Loading Time Series Set from file '" << sarg1 << "' with N=" << iarg1 << ", L=" << iarg2 << ", and D=" << iarg3 << "." << endl; res = loadDataSet(new TimeSeriesSet(sarg1.c_str(), iarg1, iarg2, iarg3)); if (res >= 0) { *out << "Dataset successfully loaded. Index: " << res << endl; res = 0; } else { *out << "Failed to load dataset." << endl; } break; case _OSAVE_TSS: *in >> iarg1; *in >> sarg2; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Saving Time Series Set " << iarg1 << ":" << t->name << " to file '" << sarg2 << "'." << endl; res = saveDataSet(iarg1, sarg2.c_str(), true); if (res == 0) *out << "Dataset successfully saved." << endl; break; case _DROP_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Dropping Time Series Set " << iarg1 << ":" << t->name << "." << endl; res = dropDataSet(iarg1); break; case _RAND_TSS: *in >> iarg1 >> iarg2 >> iarg3; *out << "Generating random Time Series Set with N=" << iarg1 << ", L=" << iarg2 << ", and range=" << iarg3 << "." << endl; res = loadDataSet(&TimeSeriesSet::randomSet(iarg1, iarg2, iarg3)); if (res >= 0) { *out << "Dataset successfully loaded. Index: " << res << endl; res = 0; } else { *out << "Failed to load dataset." << endl; } break; case _LIST_TSS: printDataSets(out); break; case _NORM_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Normalizing Time Series Set " << iarg1 << ":" << t->name << "." << endl; res = normalizeDataSet(iarg1); break; case _KSIM_TSS: *in >> iarg1 >> iarg2 >> iarg3 >> iarg4 >> iarg5 >> iarg6 >> iarg7; checkIndex(iarg1); checkIndex(iarg2); t = dataSets[iarg1]; *out << "Getting the kSimilar for Time Series Set " << iarg1 << ":" << t->name; t = dataSets[iarg2]; *out << ", query string at " << iarg3 << " in dataset " << iarg2 << ":" << t->name; *out << " in interval [" << iarg4 << "," << iarg5 << "] with k=" << iarg6 << " and strict=" << iarg7 << "." << endl; dparg1 = t->getInterval(iarg3,TimeInterval(iarg4, iarg5)).getData(); kSimilar(iarg1, vector<double>(dparg1, dparg1 + (iarg5 - iarg4 + 1)), TimeInterval(iarg4, iarg5), iarg6, iarg7); break; case _OUTLIER_TSS: *in >> iarg1 >> iarg2 >> iarg3; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Gettind dominant outlier on Time Series Set " << iarg1 << ":" << t->name << " in the range [" << iarg2 << ", " << iarg3 << "]." << endl; dominantOutlier(iarg1, TimeInterval(iarg2, iarg3)); break; case _GROUP_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << ((groupings[iarg1] != NULL)?"Regrouping":"Grouping") << " Time Series Set " << iarg1 << ":" << t->name << " with ST " << defaultST << "." << endl; genGrouping(iarg1, defaultST); break; case _NGROUP_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << ((groupings[iarg1] != NULL)?"Regrouping":"Grouping") << " Time Series Set " << iarg1 << ":" << t->name << " with ST " << defaultST << " (naive)." << endl; genNaiveGrouping(iarg1, defaultST); break; case _GROUP_ST_TSS: *in >> iarg1; *in >> darg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << ((groupings[iarg1] == NULL)?"Grouping":"Regrouping") << " Time Series Set " << iarg1 << ":" << t->name << " with ST " << darg1 << "." << endl; genGrouping(iarg1, darg1); break; case _NGROUP_ST_TSS: *in >> iarg1; *in >> darg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << ((groupings[iarg1] == NULL)?"Grouping":"Regrouping") << " Time Series Set " << iarg1 << ":" << t->name << " with ST " << darg1 << " (naive)." << endl; genNaiveGrouping(iarg1, darg1); break; case _LOAD_GROUP_TSS: *in >> iarg1; *in >> sarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Loading grouping data for Time Series Set " << iarg1 << ":" << t->name << " at " << sarg1 << "." << endl; res = loadGrouping(iarg1, sarg1.c_str()); break; case _SAVE_GROUP_TSS: *in >> iarg1; *in >> sarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Saving grouping data for Time Series Set " << iarg1 << ":" << t->name << " to " << sarg1 << "." << endl; res = saveGrouping(iarg1, sarg1.c_str()); break; case _DROP_GROUP_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; *out << "Dropping grouping data for Time Series Set " << iarg1 << ":" << t->name << "." << endl; dropGrouping(iarg1); break; case _DESC_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; t->printDesc(out); break; case _PRINT_TSS: *in >> iarg1; checkIndex(iarg1); t = dataSets[iarg1]; t->printData(out); break; case _DEBUG: *in >> iarg1; *out << "Setting debug to " << iarg1 << "." << endl; debug = iarg1; break; case _SET_DEF_ST: *in >> darg1; *out << "Setting default ST to " << darg1 << "." << endl; defaultST = darg1; break; case _GET_DEF_ST: *out << "default ST = " << defaultST << "." << endl; break; } } catch (exception &e) { *out << "Caught exception attempting operation:" << endl; *out << e.what() << endl; } time = clock() - time; (*out) << "Command used " << ((float)time/CLOCKS_PER_SEC) << " seconds." << endl << endl; count++; } return 0; }