private List <SMParameterValue> changeBoundaries(int exptID, int defID, RatControlDataContext db) { int?FirstRCEID = null; int?LastRCEID = null; db.GetFirstRCE(exptID, defID, ref FirstRCEID); db.GetLastRCE(exptID, defID, ref LastRCEID); if (FirstRCEID == null || LastRCEID == null) { Trace.WriteLine("RCEIDs are null"); } else { var Features = db.ExecuteQuery <double?>(@"SELECT Details.value('(//SetRewardPluginDetails/@Feature)[1]', 'float') AS A1 FROM RatControlEvents WHERE ExptID = {0} AND RatEventsID >= {1} AND RatEventsID <= {2} AND Details.value('(//SetRewardPluginDetails/@RandOn)[1]', 'bit') = 0 AND EventType = 9 ORDER BY A1 DESC", exptID.ToString(), FirstRCEID.ToString(), LastRCEID.ToString()).ToArray(); var Completed = db.ExecuteQuery <int?>(@"SELECT Details.value('(//SetRewardPluginDetails/@Completed)[1]', 'int') AS A1 FROM RatControlEvents WHERE ExptID = {0} AND RatEventsID >= {1} AND RatEventsID <= {2} AND Details.value('(//SetRewardPluginDetails/@RandOn)[1]', 'bit') = 0 AND EventType = 9 ORDER BY A1 DESC", exptID.ToString(), FirstRCEID.ToString(), LastRCEID.ToString()).ToArray(); int nevents = Features.Count(); int n = 0; for (int i = 0; i < nevents; i++) { if ((Features[i] != null) & (Completed[i] == 1)) { n++; } } // Convert angles into distance from target angle Double[] Dists = new double[n]; n = 0; for (int i = 0; i < nevents; i++) { if ((Features[i] != null) & (Completed[i] == 1)) { Dists[n] = Math.Abs(T - (double)Features[i]); n++; } } // Sort the distances from closest to farthest Array.Sort(Dists); // Find the distance of the 35% farthest one int psampnum = (int)Math.Round(n * pTarget / 100); var w = Dists[psampnum]; LB = T - w; UB = T + w; } List <SMParameterValue> newParams = updateSMParams(); return(newParams); }
private void jumpTarget(int exptID, int defID, RatControlDataContext db) { int?FirstRCEID = null; int?LastRCEID = null; db.GetFirstRCE(exptID, defID, ref FirstRCEID); db.GetLastRCE(exptID, defID, ref LastRCEID); if (FirstRCEID == null || LastRCEID == null) { Trace.WriteLine("RCEIDs are null"); } else { double upperEdge = TargetEdgeDist; double lowerEdge = -TargetEdgeDist; double prevT = T; // Record previous target location before updating it. double bound1 = lowerEdge; // Bounds of available intervals double bound2 = prevT - MinJumpDist; double bound3 = prevT + MinJumpDist; double bound4 = upperEdge; double intvLen1 = 0; // Length of lower available interval made up by bound1 to bound2 double intvLen2 = 0; // Length of upper available interval made up by bound3 to bound4 // Keep interval length as zero if target is too close to the edge if (bound2 > bound1) { // previous target is very close to the upper edge intvLen1 = bound2 - bound1; } if (bound4 > bound3) { // previous target is very close to the lower edge intvLen2 = bound4 - bound3; } // Pick a random location within the two intervals Random random = new Random(); double randomTargetLoc = random.NextDouble() * (intvLen1 + intvLen2); if (randomTargetLoc > intvLen1) { // previous target is very close to the upper edge T = bound3 + randomTargetLoc - intvLen1; } else { // previous target is very close to the lower edge T = bound1 + randomTargetLoc; } } }
private Status evaluatePerformance(int exptID, int defID, RatControlDataContext db) { int?FirstRCEID = null; int?LastRCEID = null; db.GetFirstRCE(exptID, defID, ref FirstRCEID); db.GetLastRCE(exptID, defID, ref LastRCEID); int numOfRewardedTrials; double percentRewarded; // number of trials in previous session int[] query1 = db.ExecuteQuery <int>(@"SELECT RatEventsID AS param6 FROM RatControlEvents WHERE ExptID = {0} AND RatEventsID >= {1} AND RatEventsID <= {2} AND Details.value('(//SetRewardPluginDetails/@RandOn)[1]', 'bit') = 0", ExptID.ToString(), FirstRCEID.ToString(), LastRCEID.ToString()).ToArray(); int numOfTrials = query1.Count(); // int numOfTrials = ScriptHelper.CountNumEntries(exptID, JSPressState, defID, JSPressSubFSM, db); Trace.WriteLine("Number of Trials: " + numOfTrials); // Evaluate number of trials and percentage if (numOfTrials < MinNumOfTrials) { return(Status.Good); Trace.WriteLine("Too Few Trials"); } else { int[] query2 = db.ExecuteQuery <int>(@"SELECT RatEventsID AS param6 FROM RatControlEvents WHERE ExptID = {0} AND RatEventsID >= {1} AND RatEventsID <= {2} AND Details.value('(//SetRewardPluginDetails/@RandOn)[1]', 'bit') = 0 AND Details.value('(//SetRewardPluginDetails/@Reward)[1]', 'int') > 0", ExptID.ToString(), FirstRCEID.ToString(), LastRCEID.ToString()).ToArray(); numOfRewardedTrials = query2.Count(); // numOfRewardedTrials = ScriptHelper.CountNumEntries(exptID, RewardState, defID, RewardSubFSM, db); percentRewarded = (double)numOfRewardedTrials / (double)numOfTrials * 100; Trace.WriteLine("Percentage Rewarded: " + percentRewarded + "%"); if (percentRewarded < MinRewarded) { return(Status.Hard); } else if (percentRewarded > MaxRewarded) { return(Status.Easy); } else { return(Status.Good); } } }