/// <inheritdoc /> public void CalculateScore(IGenome g) { // try rewrite Rules.Rewrite(g); // decode IMLMethod phenotype = CODEC.Decode(g); double score; // deal with invalid decode if (phenotype == null) { score = BestComparer.ShouldMinimize ? Double.PositiveInfinity : Double.NegativeInfinity; } else { var context = phenotype as IMLContext; if (context != null) { context.ClearContext(); } score = ScoreFunction.CalculateScore(phenotype); } // now set the scores g.Score = score; g.AdjustedScore = score; }
/// <summary> /// Background worker - Finding spectra. /// </summary> private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // Find the lonely citrullinations Validation.FindLonelyCitrullinatedSpectra(); // Loop through all of the lone citrullinated validation results. TODO: Decide how to score lone citrullinated spectrum. foreach (ValResult result in Validation.loneCitValResults) { result.ModifiedSpectra = ScoreFunction.ScoreLoneCitrullinationSpectra(result.ModifiedSpectra); } if (FileReader.fileLoadMode == FileLoadMode.ResultFile) { FileReader.LoadQuantifiedLoneCitSpectra(); } }
/// <summary> /// Returns the maximum-scoring element from the given list. /// </summary> static public T GetMaxElement <T>(IEnumerable <T> inList, ScoreFunction <T> inDelegate) { T maxVal = default(T); float maxScore = float.MinValue; float score; foreach (var element in inList) { score = inDelegate(element); if (score > maxScore) { maxScore = score; maxVal = element; } } return(maxVal); }
/// <summary> /// Background worker - Finding spectra. /// </summary> private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // Parse the parent mass error. TODO: Maybe secure against different settings double bgwPMError = Convert.ToDouble(e.Argument, FileReader.NumberFormat); // Find the arginine containing spectra Validation.FindArginineSpectra(); // Find the complementary spectra Validation.FindComplimentaryCitrullinationScans(bgwPMError); // Loop through all of the validation results foreach (ValResult result in Validation.argValResults) { // Score the arginine spectra result.ArgSpectraDictionary = ScoreFunction.ScoreArginineSpectra(result.ArgSpectraDictionary); } if (FileReader.fileLoadMode == FileLoadMode.ResultFile) { FileReader.LoadQuantifiedArgSpectra(); } }
/// <summary> /// Returns the maximum-scoring element from the given list. /// </summary> static public T GetMaxElement <T>(ListSlice <T> inList, ScoreFunction <T> inDelegate) { T maxVal = default(T); float maxScore = float.MinValue; float score; T element; for (int i = 0; i < inList.Length; ++i) { element = inList[i]; score = inDelegate(element); if (score > maxScore) { maxScore = score; maxVal = element; } } return(maxVal); }
/// <summary> /// Background worker - Finding spectra. /// </summary> private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // Parse the parent mass error double bgwPMError = Convert.ToDouble(e.Argument, FileReader.NumberFormat); // Find the citrullinated spectra Validation.FindCitrullinatedSpectra(); // Find the complementary spectra Validation.FindComplementaryArginineSpectra(bgwPMError); // Loop through all of the validation results foreach (ValResult result in Validation.citValResults) { // Score the citrullinated spectra result.CitSpectraDictionary = ScoreFunction.ScoreCitrullinationSpectra(result.CitSpectraDictionary); } if (FileReader.fileLoadMode == FileLoadMode.ResultFile) { FileReader.LoadQuantifiedCitSpectra(); } }
public BinaryHeap(ScoreFunction f) { this.scoreFunction = f; this.content = new TArray <HeapNode>(); }
private static float DoMiniMax(Vector2 nextMove, ScoredMove scoredMove, int depth, bool maximizingPlayer, GameState gs, StrategyHandler sh, ScoreFunction sf) { // Create a copy of the gamestate and apply the move option GameState gsTemp = gs.Copy(); gsTemp.AddPoint(nextMove, !maximizingPlayer); if (depth <= 0) { return(sf.ComputeScore(nextMove, gsTemp)); } List <Vector2> options = sh.ComputeOptions(gsTemp, maximizingPlayer); if (maximizingPlayer) { float max = float.MinValue; foreach (Vector2 option in options) { // Execute minimax on the new game state float value = DoMiniMax(option, scoredMove, depth - 1, false, gsTemp, sh, sf); max = Mathf.Max(max, value); } return(max); } else { float min = float.MaxValue; foreach (Vector2 option in options) { // Execute minimax on the new game state float value = DoMiniMax(option, scoredMove, depth - 1, true, gsTemp, sh, sf); min = Mathf.Min(min, value); } return(min); } }
public static Vector2 GetBestMove(bool player1, GameState gs, StrategyHandler sh, ScoreFunction sf) { // First let the strategy handler determine all possible move options for this round List <Vector2> options = sh.ComputeOptions(gs, player1); // Convert the options to scored moves List <ScoredMove> scoredMoves = options.ConvertAll(o => new ScoredMove(o)); foreach (ScoredMove scoredMove in scoredMoves) { // The depth specified is the number of moves after the first next move float value = DoMiniMax(scoredMove.Move, scoredMove, 1, !player1, gs, sh, sf); // Debug.Log("==============================> score: " + value); // Debug.Log("-----> Move: " + scoredMove.Move); scoredMove.SetScore(value); } float bestScore; if (player1) { bestScore = float.MinValue; } else { bestScore = float.MaxValue; } ScoredMove bestMove = scoredMoves[0]; foreach (ScoredMove scoredMove in scoredMoves) { if (player1) { // Maximize the score if minimax is used for player 1 if (scoredMove.Score > bestScore) { bestScore = scoredMove.Score; bestMove = scoredMove; } } else { // Minimize the score if minimax is used for player 2 if (scoredMove.Score < bestScore) { bestScore = scoredMove.Score; bestMove = scoredMove; } } } Vector2 move = bestMove.Move; storedOptions = options; return(move); }
public static LinearDecomposition Compute(Datastructures.Graph graph, ScoreFunction scoreFunction) { // We solve finding an ordering for each connected component of the graph seperately List<BitSet> connectedComponents = DepthFirstSearch.ConnectedComponents(graph); // The final sequence that we will return List<int> sequence = new List<int>(); // Shorthand notation int n = graph.Size; foreach (BitSet connectedComponent in connectedComponents) { // Set of unprocessed vertices BitSet right = connectedComponent; // Set of processed vertices BitSet left = new BitSet(0, n); // The initial is selected by a certain strategy (in this case a double BFS) int init = Heuristics.Bfs(graph, Heuristics.Bfs(graph, connectedComponent.Last())); // Place init in the sequence sequence.Add(init); left += init; right -= init; // Continue while not all unprocessed vertices are moved while (!right.IsEmpty) { int chosen = Heuristics.TrivialCases(graph, left, right); // If chosen has not been set it means that no trivial case was found // Depending on the criteria for the next vertex we call a different algorithm if (chosen == -1) { switch (scoreFunction) { case ScoreFunction.LeastUncommonNeighbor: chosen = LeastUncommonNeighbor(graph, left, right); break; case ScoreFunction.RelativeNeighborhood: chosen = RelativeNeighborhood(graph, left, right); break; case ScoreFunction.LeastCutValue: chosen = LeastCutValue(graph, left, right); break; } } // This should never happen; a selection criteria should always return some vertex if (chosen == -1) throw new Exception("No vertex is chosen for next step in the heuristic"); // Add/remove the next vertex in the appropiate sets sequence.Add(chosen); left += chosen; right -= chosen; } } return new LinearDecomposition(graph, sequence); }
/// <summary> /// Returns the minimum-scoring element from the given list. /// </summary> static public T GetMinElement <T>(T[] inList, int inStartIndex, int inLength, ScoreFunction <T> inDelegate) { return(GetMinElement(new ListSlice <T>(inList, inStartIndex, inLength), inDelegate)); }
public void SetScoreFunction(ScoreFunction sf) { this.sf = sf; }
public static CommonConfiguration GetRecommendationConfiguration() { SqlServerContext _client = new SqlServerContext(Mars_Database_Key); CommonConfiguration result = new CommonConfiguration(); try { DbCommand command = _client.GetStoredProcCommand("ps_Config_GetCommonConfig"); using (IDataReader reader = _client.ExecuteReader(command)) { #region Config_WebSite while (reader.Read()) { int webSiteId = SqlDataHelper.GetIntValue("WebSiteId", reader); result.WebSitesValues.Add((WebSites)webSiteId, new WebSite { WebSiteId = (WebSites)webSiteId, Name = SqlDataHelper.GetStringValue("Name", reader), SelectionMethodId = (SelectionMethods)SqlDataHelper.GetIntValue("SelectionMethodId", reader), StrongestInteractionName = SqlDataHelper.GetStringValue("StrongestInteractionName", reader), DownloadFriendsLikes = SqlDataHelper.GetBoolValue("DownloadFriendsLikes", reader) }); } #endregion #region WebSiteAlgorithms reader.NextResult(); while (reader.Read()) { WebSites webSiteId = (WebSites)SqlDataHelper.GetIntValue("WebSiteId", reader); int algorithmId = SqlDataHelper.GetIntValue("AlgorithmId", reader); result.DeclareAlgorithm(webSiteId, algorithmId); } reader.NextResult(); #endregion #region AlgorithmGraphActions while (reader.Read()) { int algorithmId = SqlDataHelper.GetIntValue("AlgorithmId", reader); int graphActionId = SqlDataHelper.GetIntValue("GraphActionId", reader); result.DeclareGraphAction(algorithmId, graphActionId); } reader.NextResult(); #endregion #region AggregationFunctions List <AggregationFunction> aggregationFunctions = new List <AggregationFunction>(); while (reader.Read()) { AggregationFunction af = new AggregationFunction(); af.Id = SqlDataHelper.GetIntValue("Id", reader); af.Name = SqlDataHelper.GetStringValue("Name", reader); aggregationFunctions.Add(af); } reader.NextResult(); #endregion #region ScoreFunctions List <ScoreFunction> scoreFunctions = new List <ScoreFunction>(); while (reader.Read()) { ScoreFunction sf = new ScoreFunction(); sf.Id = SqlDataHelper.GetIntValue("Id", reader); sf.Name = SqlDataHelper.GetStringValue("Name", reader); scoreFunctions.Add(sf); } reader.NextResult(); #endregion #region ScoreFunctionParameters while (reader.Read()) { ScoreFunctionParameter sfp = new ScoreFunctionParameter(); sfp.Id = SqlDataHelper.GetIntValue("Id", reader); sfp.Parameter2 = SqlDataHelper.GetStringValue("Parameter2", reader); sfp.Parameter1 = SqlDataHelper.GetStringValue("Parameter1", reader); sfp.Value = SqlDataHelper.GetDoubleValue("Value", reader); sfp.WebSiteId = SqlDataHelper.GetIntValue("WebSiteId", reader); int graphActionId = SqlDataHelper.GetIntValue("GraphActionId", reader); int algorithmId = SqlDataHelper.GetIntValue("AlgorithmId", reader); WebSites webSiteId = (WebSites)SqlDataHelper.GetIntValue("WebSiteId", reader); result.AddScoreFunctionParameterToGraphAction(webSiteId, algorithmId, graphActionId, sfp); } reader.NextResult(); #endregion #region AggregationFunctionParameters while (reader.Read()) { AggregationFunctionParameter afp = new AggregationFunctionParameter(); afp.Id = SqlDataHelper.GetIntValue("Id", reader); afp.Name = SqlDataHelper.GetStringValue("Name", reader); afp.Value = SqlDataHelper.GetDoubleValue("Value", reader); int algorithmId = SqlDataHelper.GetIntValue("AlgorithmId", reader); WebSites webSiteId = (WebSites)SqlDataHelper.GetIntValue("WebSiteId", reader); result.AddAggregationFunctionParameterToAlgorithm(webSiteId, algorithmId, afp); } reader.NextResult(); List <RecommendationQuery> queries = new List <RecommendationQuery>(); while (reader.Read()) { RecommendationQuery query = new RecommendationQuery(); query.Id = SqlDataHelper.GetIntValue("Id", reader); query.QueryContent = SqlDataHelper.GetStringValue("Query", reader); queries.Add(query); } reader.NextResult(); List <GremlinScript> scripts = new List <GremlinScript>(); while (reader.Read()) { GremlinScript script = new GremlinScript(); script.Id = SqlDataHelper.GetIntValue("Id", reader); script.Script = SqlDataHelper.GetStringValue("Script", reader); scripts.Add(script); } reader.NextResult(); List <MirrorQuery> mirrorQueries = new List <MirrorQuery>(); while (reader.Read()) { MirrorQuery query = new MirrorQuery(); query.Id = SqlDataHelper.GetIntValue("Id", reader); query.QueryContent = SqlDataHelper.GetStringValue("MirrorQuery", reader); mirrorQueries.Add(query); } reader.NextResult(); List <MirrorScripts> mirrorScripts = new List <MirrorScripts>(); while (reader.Read()) { MirrorScripts script = new MirrorScripts(); script.Id = SqlDataHelper.GetIntValue("Id", reader); script.MirrorScript = SqlDataHelper.GetStringValue("MirrorScript", reader); mirrorScripts.Add(script); } reader.NextResult(); #endregion #region GraphActions while (reader.Read()) { int graphActionId = SqlDataHelper.GetIntValue("Id", reader); string name = SqlDataHelper.GetStringValue("Name", reader); int expiration = SqlDataHelper.GetIntValue("Expiration", reader); int?queryId = SqlDataHelper.GetNullableInt("QueryId", reader); int?scriptId = SqlDataHelper.GetNullableInt("GremlinScriptId", reader); int scoreFunctionId = SqlDataHelper.GetIntValue("ScoreFunctionId", reader); int?mirrorQueryId = SqlDataHelper.GetNullableInt("MirrorQueryId", reader); int?mirrorScriptId = SqlDataHelper.GetNullableInt("MirrorScriptId", reader); RecommendationQuery query = queries.Find(q => q.Id == queryId); GremlinScript script = scripts.Find(s => s.Id == scriptId); ScoreFunction scoreFunction = scoreFunctions.Find(sf => sf.Id == scoreFunctionId); MirrorQuery mirrorQuery = null; MirrorScripts mirrorScript = null; if (mirrorQueryId.HasValue) { mirrorQuery = mirrorQueries.Find(mq => mq.Id == mirrorQueryId.Value); } if (mirrorScriptId.HasValue) { mirrorScript = mirrorScripts.Find(ms => ms.Id == mirrorScriptId.Value); } foreach (GraphAction ga in result.GetGraphActions(graphActionId)) { ga.Name = name; ga.Expiration = expiration; ga.Query = query; ga.Script = script; ga.ScoreFunction = scoreFunction; ga.MirrorQuery = mirrorQuery; ga.MirrorScript = mirrorScript; } } reader.NextResult(); #endregion #region Algorithms while (reader.Read()) { int algorithmId = SqlDataHelper.GetIntValue("Id", reader); string name = SqlDataHelper.GetStringValue("Name", reader); bool isStandardQuery = SqlDataHelper.GetBoolValue("IsStandardQuery", reader); int aggregationFunctionId = SqlDataHelper.GetIntValue("AggregationFunctionId", reader); AggregationFunction af = aggregationFunctions.Find(a => a.Id == aggregationFunctionId); foreach (Algorithm algorithm in result.GetAlgorithms(algorithmId)) { algorithm.Name = name; algorithm.IsStandardQuery = isStandardQuery; algorithm.AggregationFunction = af; } } reader.NextResult(); #endregion #region ContentTypeDistribution while (reader.Read()) { ContentTypeDistribution distribution = new ContentTypeDistribution(); distribution.Id = SqlDataHelper.GetIntValue("Id", reader); distribution.Name = SqlDataHelper.GetStringValue("Name", reader); result.Distributions[distribution.Id] = distribution; } reader.NextResult(); #endregion #region ContentTypeQuota while (reader.Read()) { ContentTypeQuota quota = new ContentTypeQuota(); quota.Id = SqlDataHelper.GetIntValue("Id", reader); quota.Name = SqlDataHelper.GetStringValue("Name", reader); quota.Quota = SqlDataHelper.GetDoubleValue("Quota", reader); int distributionId = SqlDataHelper.GetIntValue("DistributionId", reader); result.AddQuotaToDistribution(distributionId, quota); } reader.NextResult(); #endregion #region ContentTypeValues while (reader.Read()) { ContentTypeValues value = new ContentTypeValues(); value.Id = SqlDataHelper.GetIntValue("Id", reader); value.Name = SqlDataHelper.GetStringValue("Name", reader); value.MongoName = SqlDataHelper.GetStringValue("MongoName", reader); value.IsString = SqlDataHelper.GetBoolValue("IsString", reader); value.Value = SqlDataHelper.GetStringValue("Value", reader); int quotaId = SqlDataHelper.GetIntValue("QuotaId", reader); result.AddValueToQuota(quotaId, value); } #endregion } } catch (Exception e) { Logger.Current.Error("GetRecommendationConfiguration", "Error loading configuration", e); } return(result); }