public long?GetSolutionIdFromOutputs(RlmGetSolutionIdFromOutputs data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetSolutionIdFromOutputs(data.OutputValuesPair)); }
public IEnumerable <RlmIODetails>[] GetCaseIODetails(RlmGetCaseIODetailsParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetCaseIODetails(data.CaseId)); }
public IEnumerable <RlmLearnedCase> GetLearnedCases(RlmGetLearnedCasesParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetLearnedCases(data.RneuronId, data.SolutionId, data.Scale)); }
public long?GetNextPrevLearnedCaseId(RlmGetNextPrevLearnedCaseIdParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetNextPreviousLearnedCaseId(data.CaseId.Value, data.IsNext)); }
private IEnumerable <RlmSessionHistory> getSessionsWithSignificantLearning(RlmFilterResultParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetSignificantLearningEvents(data.Skip, data.Take)); }
public IEnumerable <RlmCaseHistory> GetSessionCases(RlmGetSessionCaseParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetSessionCaseHistory(data.SessionId, data.Skip, data.Take)); }
public IEnumerable <RlmLearnedSessionDetails> GetSessionIODetails(RlmGetSessionDetailsParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetSessionIODetails(data.SessionIds)); }
private IEnumerable <RlmSessionHistory> getSessionHistory(RlmFilterResultParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetSessionHistory(data.Skip, data.Take)); }
public RlmCaseIOHistory GetCaseInputOutputDetails(RlmGetCaseIOParams data) { RlmNetworkWebAPI network = LoadNetworkFromCache(data); RlmSessionCaseHistory hist = network.SessionCaseHistory; return(hist.GetCaseIOHistory(data.CaseId, data.RneuronId, data.SolutionId)); }
private void MqttClient_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { string topic = e.Topic; string msg = Encoding.UTF8.GetString(e.Message); if (topic == "init") { TOPIC_UID = msg; //Get unique id from client subscribe("create_load_network"); subscribe("configure_network"); subscribe("start_session"); subscribe("run_cycle"); subscribe("score_cycle"); subscribe("end_session"); subscribe("sessions"); subscribe("session_cases"); subscribe("io_details"); subscribe("disconnect"); publish(msg + "/init_result", TOPIC_UID); } else if (topic == createTopic("create_load_network")) { CreateLoadNetworkParams data = JsonConvert.DeserializeObject <CreateLoadNetworkParams>(msg); network = new RlmNetwork(data.RlmName); if (!network.LoadNetwork(data.NetworkName)) { IEnumerable <RlmIO> inputs = data.Inputs.Select(a => new RlmIO(a.IOName, a.DotNetType, a.Min, a.Max, a.InputType)).ToList(); IEnumerable <RlmIO> outputs = data.Outputs.Select(a => new RlmIO(a.IOName, a.DotNetType, a.Min, a.Max)).ToList(); network.NewNetwork(data.NetworkName, inputs, outputs); } publish(createTopic("create_network_result"), "Network successfully loaded!"); } else if (topic == createTopic("configure_network")) { RlmSettingsParams data = JsonConvert.DeserializeObject <RlmSettingsParams>(msg); network.NumSessions = data.NumSessions; network.StartRandomness = data.StartRandomness; network.EndRandomness = data.EndRandomness; network.MaxLinearBracket = data.MaxLinearBracket; network.MinLinearBracket = data.MinLinearBracket; publish(createTopic("configure_result"), "Network successfully configured!"); } else if (topic == createTopic("start_session")) { long sessionId = network.SessionStart(); publish(createTopic("start_session_result"), sessionId.ToString()); } else if (topic == createTopic("run_cycle")) { RunCycleParams data = JsonConvert.DeserializeObject <RunCycleParams>(msg); var retVal = new CycleOutputParams(); var inputsCycle = new List <RlmIOWithValue>(); foreach (var ins in data.Inputs) { inputsCycle.Add(new RlmIOWithValue(network.Inputs.Where(item => item.Name == ins.IOName).First(), ins.Value)); } var Cycle = new RlmCycle(); RlmCyclecompleteArgs cycleOutput = null; // supervised training if (data.Outputs == null || (data.Outputs != null && data.Outputs.Count > 0)) { var outputsCycle = new List <RlmIOWithValue>(); foreach (var outs in data.Outputs) { outputsCycle.Add(new RlmIOWithValue(network.Outputs.First(a => a.Name == outs.IOName), outs.Value)); } cycleOutput = Cycle.RunCycle(network, network.CurrentSessionID, inputsCycle, data.Learn, outputsCycle); } else // unsupervised training { cycleOutput = Cycle.RunCycle(network, network.CurrentSessionID, inputsCycle, data.Learn); } if (cycleOutput != null) { retVal = new CycleOutputParams { RlmType = cycleOutput.RlmType, CycleId = cycleOutput.CycleOutput.CycleID }; var outputs = cycleOutput.CycleOutput.Outputs; for (int i = 0; i < outputs.Count(); i++) { RlmIOWithValue output = outputs.ElementAt(i); retVal.Outputs.Add(new RlmIOWithValuesParams() { IOName = output.Name, Value = output.Value }); } } var resultStr = JsonConvert.SerializeObject(retVal); publish(createTopic("run_cycle_result"), resultStr); } else if (topic == createTopic("score_cycle")) { ScoreCycleParams data = JsonConvert.DeserializeObject <ScoreCycleParams>(msg); network.ScoreCycle(data.CycleID, data.Score); publish(createTopic("score_cycle_result"), "Scoring cycle..."); } else if (topic == createTopic("end_session")) { SessionEndParams data = JsonConvert.DeserializeObject <SessionEndParams>(msg); network.SessionEnd(data.SessionScore); publish(createTopic("end_session_result"), "Session ended!"); } else if (topic == createTopic("sessions")) { dynamic data = JsonConvert.DeserializeObject <dynamic>(msg); string dbName = (String)data.RlmName; bool withSignificantLearning = Convert.ToBoolean(((String)data.WithLearning).ToLower()); int? skip = Convert.ToInt32(((Int32)data.Skip)); int? take = Convert.ToInt32(((Int32)data.Take)); if (skip == 0) { skip = null; } if (take == 0) { take = null; } string resultStr = ""; if (withSignificantLearning) { resultStr = JsonConvert.SerializeObject(getSessionsWithSignificantLearning(new RlmFilterResultParams { Skip = skip, Take = take, RlmName = dbName })); } else { resultStr = JsonConvert.SerializeObject(getSessionHistory(new RlmFilterResultParams { Skip = skip, Take = take, RlmName = dbName })); } publish(createTopic("sessions_result"), resultStr); } else if (topic == createTopic("session_cases")) { RlmGetSessionCaseParams data = JsonConvert.DeserializeObject <RlmGetSessionCaseParams>(msg); RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); var resultStr = JsonConvert.SerializeObject(hist.GetSessionCaseHistory(data.SessionId, data.Skip, data.Take)); publish(createTopic("session_cases_result"), resultStr); } else if (topic == createTopic("io_details")) { RlmGetCaseIOParams data = JsonConvert.DeserializeObject <RlmGetCaseIOParams>(msg); RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); var resultStr = JsonConvert.SerializeObject(hist.GetCaseIOHistory(data.CaseId, data.RneuronId, data.SolutionId)); publish(createTopic("io_details_result"), resultStr); } else if (topic == createTopic("disconnect")) { if (MQTT_CLIENT != null && MQTT_CLIENT.IsConnected) { MQTT_CLIENT.Disconnect(); } } }
private IEnumerable <RlmSessionHistory> getSessionsWithSignificantLearning(RlmFilterResultParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetSignificantLearningEvents(data.Skip, data.Take)); }
private IEnumerable <RlmSessionHistory> getSessionHistory(RlmFilterResultParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetSessionHistory(data.Skip, data.Take)); }
public IEnumerable <RlmLearnedSessionDetails> GetSessionIODetails(RlmGetSessionDetailsParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetSessionIODetails(data.SessionIds)); }
static void Main(string[] args) { Console.WriteLine("\n\nOptions: \n\n[1] = All Games Played \n[2] = All Games W/ Significant Learning \n[3] = Save As Html \n[Esc] = Exit\n\n"); ConsoleKeyInfo input = Console.ReadKey(); var userInput = 0; switch (input.Key) { case ConsoleKey.D1: userInput = 1; break; case ConsoleKey.D2: userInput = 2; break; case ConsoleKey.D3: userInput = 3; break; case ConsoleKey.Escape: userInput = 4; break; default: userInput = 1; break; } getDbName: Console.Write("\n\nEnter database name: "); string dbName = Console.ReadLine(); if (string.IsNullOrEmpty(dbName)) { Console.WriteLine("Empty database name not allowed."); goto getDbName; } var sessionCaseApi = new RlmSessionCaseHistory(dbName); bool dbOk = false; if (userInput == 1) { getResults(sessionCaseApi, 1, out dbOk); if (!dbOk) { goto getDbName; } } else if (userInput == 2) { getResults(sessionCaseApi, 2, out dbOk); if (!dbOk) { goto getDbName; } } else if (userInput == 3) { GenerateHtmlFile(sessionCaseApi); } else if (userInput == 4) { Environment.Exit(0); } Console.ReadLine(); }
public IEnumerable <RlmIODetails>[] GetCaseIODetails(RlmGetCaseIODetailsParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetCaseIODetails(data.CaseId)); }
public IEnumerable <RlmLearnedCase> GetLearnedCases(RlmGetLearnedCasesParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetLearnedCases(data.RneuronId, data.SolutionId, data.Scale)); }
public long?GetSolutionIdFromOutputs(RlmGetSolutionIdFromOutputs data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetSolutionIdFromOutputs(data.OutputValuesPair)); }
public long?GetRneuronIdFromInputs(RlmGetRneuronIdFromInputs data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetRneuronIdFromInputs(data.InputValuesPair)); }
public RlmCaseIOHistory GetCaseInputOutputDetails(RlmGetCaseIOParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetCaseIOHistory(data.CaseId, data.RneuronId, data.SolutionId)); }
public RLVCore(string databaseName) { rlmHistory = new RlmSessionCaseHistory(databaseName); }
public long?GetNextPrevLearnedCaseId(RlmGetNextPrevLearnedCaseIdParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetNextPreviousLearnedCaseId(data.CaseId.Value, data.IsNext)); }
private static void GenerateHtmlFile(RlmSessionCaseHistory sessionCaseApi) { getMode: Console.WriteLine("\n\nGenerating an HTML file. Please select an option below."); Console.WriteLine("\nOptions: [1] = All Games, [2] = All Games W/ Significant Learning"); ConsoleKeyInfo userInput = Console.ReadKey(); int mode = 0; if (userInput.Key == ConsoleKey.D1) { mode = 1; } else if (userInput.Key == ConsoleKey.D2) { mode = 2; } else { Console.WriteLine("\nYou're not entering the right input. Try again."); goto getMode; } Console.WriteLine("\nGenerating html file..."); var sessions = mode == 1? sessionCaseApi.GetSessionHistory() : sessionCaseApi.GetSignificantLearningEvents(); var mainUL = "<ul>"; foreach (var s in sessions) { mainUL += $"<li style='list-style:none;'>Session# {s.SessionNumber}"; mainUL += $"<table style='width:25%;font-size:10px;'><thead align='left'><tr><th>Id</th><th>Score</th><th>DateTimeStart</th><th>DateTimeStop</th></tr></thead><tbody><tr><td>{s.Id}</td><td>{s.SessionScore}</td><td>{s.DateTimeStart}</td><td>{s.DateTimeStop}</td></tr></tbody></table>"; var cases = sessionCaseApi.GetSessionCaseHistory(s.Id); if (cases.Count() == 0) { continue; } mainUL += "<br/><span>CASES:</span>"; var caseUL = "<ul>"; foreach (var cd in cases) { caseUL += $"<br/><li style='list-style:none;'>Case# {cd.RowNumber}"; caseUL += $"<table style='width:25%;font-size:10px;'><thead align='left'><tr><th>CaseId</th><th>Score</th><th>DateTimeStart</th><th>DateTimeStop</th></tr></thead style='border-style:solid;border-width:1px;'><tbody><tr><td>{cd.Id}</td><td>{cd.CycleScore}</td><td>{cd.DateTimeStart}</td><td>{cd.DateTimeStop}</td></tr></tbody></table>"; var ioTable = "<table style='width:25%;font-size:10px;'><thead align='left'><tr><th>Name</th><th>Value</th></tr></thead><tbody>"; var ioTable2 = "<table style='width:25%;font-size:10px;'><thead align='left'><tr><th>Name</th><th>Value</th></tr></thead><tbody>"; var ioDetail = sessionCaseApi.GetCaseIOHistory(cd.Id, cd.RneuronId, cd.SolutionId); foreach (var ioin in ioDetail.Inputs) { ioTable += $"<tr><td>{ioin.Name}</td><td>{ioin.Value}</td></tr>"; } foreach (var ioout in ioDetail.Outputs) { ioTable2 += $"<tr><td>{ioout.Name}</td><td>{ioout.Value}</td></tr>"; } ioTable += "</tbody></table>"; ioTable2 += "</tbody></table>"; caseUL += "<br/>IO Details<br/><br/>"; var caseIO = $"<table><th>Inputs</th><th>Outputs</th><tbody><tr><td>{ioTable}</td><td>{ioTable2}</td></tr></tbody></table>"; caseUL += caseIO; caseUL += "</li><br/>"; } caseUL += "</ul>"; mainUL += caseUL; mainUL += "</li>"; } mainUL += "</ul>"; try { string path = AppDomain.CurrentDomain.BaseDirectory + "learning_history_" + sessionCaseApi.DatabaseName + ".html"; File.WriteAllText(path, mainUL); Console.WriteLine("\n\nData successfully generated to HTML file in the following path. " + path + ""); } catch (Exception e) { Console.WriteLine("Failed to generate html file."); } }
public IEnumerable <RlmCaseHistory> GetSessionCases(RlmGetSessionCaseParams data) { RlmSessionCaseHistory hist = new RlmSessionCaseHistory(data.RlmName); return(hist.GetSessionCaseHistory(data.SessionId, data.Skip, data.Take)); }
private static void getResults(RlmSessionCaseHistory sessionCaseApi, int mode, out bool dbOk) { dbOk = true; Console.WriteLine("\nGetting results..."); var sessionHistory = mode == 1? sessionCaseApi.GetSessionHistory() : sessionCaseApi.GetSignificantLearningEvents(); if (sessionHistory.Count() == 0) { Console.WriteLine("\nYou entered an invalid database. Try again."); dbOk = false; return; } Console.WriteLine("\nRESULTS:\n"); var histStr = new StringBuilder(); //Sessions header histStr.AppendLine(string.Format("{0}{1,15}{2,20}{3,33}{4,37}", "Session", "Score", "Start", "End", "Elapse")); foreach (var h in sessionHistory) { Console.WriteLine($"Session: {h.SessionNumber}, Score: {h.SessionScore}, Start: {h.DateTimeStart}, End: {h.DateTimeStop}, Elapse: {h.Elapse}"); string resultsStr = string.Format("{0}{1,20}{2,30}{3,35}{4,30}", h.SessionNumber, h.SessionScore, h.DateTimeStart, h.DateTimeStop, h.Elapse); histStr.AppendLine(resultsStr); } if (histStr.Length > 1) { System.Windows.Forms.Clipboard.SetText(histStr.ToString()); Console.WriteLine("\n*** Results copied to clipboard! ***"); } getSession: Console.Write("\n\nEnter session number to view events. "); int session = Convert.ToInt32(Console.ReadLine()); if (session > 0) { Console.WriteLine("\nGetting events..."); var currentSession = mode == 1? sessionHistory.ElementAt(session - 1) : sessionHistory.FirstOrDefault(a => a.SessionNumber == session); var sessionEvents = sessionCaseApi.GetSessionCaseHistory(currentSession.Id); if (sessionEvents.Count() == 0) { Console.WriteLine("No events found for this session! Try another one."); goto getSession; } Console.WriteLine("\nEVENTS:\n\n"); var eventsStr = new StringBuilder(); //Events header eventsStr.AppendLine($"[Events for Session# {currentSession.SessionNumber}]\n"); eventsStr.AppendLine(string.Format("{0}{1,15}{2,20}{3,25}{4,27}", "Number", "Score", "Start", "End", "Elapse")); foreach (var evt in sessionEvents) { Console.WriteLine($"Number: {evt.RowNumber}, Score: {evt.CycleScore}, Start: {evt.DateTimeStart}, End: {evt.DateTimeStop}, Elapse: {evt.Elapse}"); string resultStr = string.Format("{0}{1,18}{2,30}{3,25}{4,20}", evt.RowNumber, evt.CycleScore, evt.DateTimeStart, evt.DateTimeStop, evt.Elapse); eventsStr.AppendLine(resultStr); } if (eventsStr.Length > 1) { System.Windows.Forms.Clipboard.SetText(eventsStr.ToString()); Console.WriteLine("\n*** Results copied to clipboard! ***"); } getEvt: eventsStr = new StringBuilder(); Console.Write("\n\nEnter event number to view input/output details. "); int cycle = Convert.ToInt32(Console.ReadLine()); if (cycle > 0) { var ioDetailsStr = new StringBuilder(); var currentCycle = sessionEvents.ElementAt(cycle - 1); var ioDetail = sessionCaseApi.GetCaseIOHistory(currentCycle.Id, currentCycle.RneuronId, currentCycle.SolutionId); eventsStr.AppendLine($"[Session# {currentSession.SessionNumber}, Case# {currentCycle.RowNumber}]\n"); eventsStr.AppendLine(string.Format("{0}{1,15}{2,20}{3,25}{4,27}", "Number", "Score", "Start", "End", "Elapse")); string resultStr = string.Format("{0}{1,18}{2,30}{3,25}{4,20}", currentCycle.RowNumber, currentCycle.CycleScore, currentCycle.DateTimeStart, currentCycle.DateTimeStop, currentCycle.Elapse); eventsStr.AppendLine(resultStr); Console.WriteLine($"\nResults for case number {cycle}"); Console.WriteLine("\nINPUTS:\n"); ioDetailsStr.AppendLine("\n\n[INPUTS:]\n"); foreach (var cycleIn in ioDetail.Inputs) { Console.WriteLine($"Name: {cycleIn.Name}, Value: {cycleIn.Value}"); ioDetailsStr.AppendLine($"Name: {cycleIn.Name}, Value: {cycleIn.Value}"); } Console.WriteLine("\nOUTPUTS:\n"); ioDetailsStr.AppendLine("\n\n[OUTPUTS:]\n"); foreach (var cycleOut in ioDetail.Outputs) { Console.WriteLine($"Name: {cycleOut.Name}, Value: {cycleOut.Value}"); ioDetailsStr.AppendLine($"Name: {cycleOut.Name}, Value: {cycleOut.Value}"); } eventsStr.AppendLine(ioDetailsStr.ToString()); if (eventsStr.Length > 1) { System.Windows.Forms.Clipboard.SetText(eventsStr.ToString()); Console.WriteLine("\n*** Results copied to clipboard! ***"); } } selectEvtSess: Console.WriteLine("\n\n[1] = New Event, [2] = New Session, [Esc] = Exit"); ConsoleKeyInfo evtSessIn = Console.ReadKey(); switch (evtSessIn.Key) { case ConsoleKey.D1: goto getEvt; case ConsoleKey.D2: goto getSession; case ConsoleKey.Escape: GenerateHtmlFile(sessionCaseApi); Environment.Exit(0); break; default: goto selectEvtSess; } } }
public RLVCore(IRlmDbData rlmDb) { rlmDb.Initialize(); rlmHistory = new RlmSessionCaseHistory(rlmDb); }