private IHSExplicitVector <HSEdgeState> __qwStepFunction(HSEdgeState basisState) { List <HSEdgeState> v2edgeStates = new List <HSEdgeState>(); double n = basisState.Vertex2.GraphEdges.Count(); IAlgebraicExpression r = IAlgebraicExpression.RealNumber((n - 2.0d) / n); IAlgebraicExpression t = IAlgebraicExpression.RealNumber(2.0d / n); foreach (QGEdge edge in basisState.Vertex2.GraphEdges) { HSEdgeState edgeState; if (edge.Vertex1 == basisState.Vertex2) { edgeState = new HSEdgeState(edge.Vertex1, edge.Vertex2); } else { edgeState = new HSEdgeState(edge.Vertex2, edge.Vertex1); } // Skip the reflected state if (edgeState.Vertex2 != basisState.Vertex1) { v2edgeStates.Add(edgeState); } } var vectorTerms = v2edgeStates.Select(s => new VectorTerm <HSEdgeState>(s, !basisState.Vertex2.IsMarked() ? t : -t)); vectorTerms = vectorTerms.Prepend((new HSEdgeState(basisState.Vertex2, basisState.Vertex1), !basisState.Vertex2.IsMarked() ? -r : r)); return(IHSExplicitVector <HSEdgeState> .VectorValue(vectorTerms)); }
private IHSExplicitVectorValue <HSEdgeState> __qwGetStartVector(IQGVertex startVertex) { List <HSEdgeState> edgeStates = new List <HSEdgeState>(); double n = startVertex.GraphEdges.Count(); IAlgebraicExpression coefficient = IAlgebraicExpression.RealNumber(1.0d / Math.Sqrt(n)); foreach (QGEdge edge in startVertex.GraphEdges) { HSEdgeState edgeState; if (edge.Vertex1 == startVertex) { edgeState = new HSEdgeState(edge.Vertex1, edge.Vertex2); } else { edgeState = new HSEdgeState(edge.Vertex2, edge.Vertex1); } edgeStates.Add(edgeState); } var vectorTerms = edgeStates.Select(s => new VectorTerm <HSEdgeState>(s, coefficient)); return(IHSExplicitVector <HSEdgeState> .VectorValue(vectorTerms)); }
private void __initializeMath() { _hs = this.CompileHilbertSpace(); var hsVector = IHSExplicitVector <HSEdgeState> .ArbitraryVector(_hs, "hs"); var op = IHSExplicitVector <HSEdgeState> .CreateLinearOperator(__qwStepFunction, "step"); _recurrenceVector = (IHSExplicitVectorValue <HSEdgeState>)hsVector.ApplyOperator(op); }
public void ResetSimulation() { if (_hs == null || _recurrenceVector == null) { throw new Exception("Cannot reset simulation because it has not yet been initialized."); } _totalStepCount = 0; _currentStep = (IHSExplicitVectorValue <HSEdgeState>)(IHSExplicitVector <HSEdgeState> .ZeroVector(_hs) + __qwGetStartVector(IQGVertex.StartVertex)); this.CurrentSimulationState = new QwasiEvaluationState(_currentStep, _totalStepCount); this.RaiseSimulationStartedEvent(new QwasiSimulationStepEventArgs(this.CurrentSimulationState, 0, _totalStepCount)); this.ApplySimulationGraphVisualizations(); }
public QwasiAnalyticsData CompileAnalytics(int stepInterval, int stepRangeStart, int stepRangeEnd) { if (stepRangeEnd < stepRangeStart) { return(new QwasiAnalyticsData()); } __initializeMath(); _currentStep = (IHSExplicitVectorValue <HSEdgeState>)(IHSExplicitVector <HSEdgeState> .ZeroVector(_hs) + __qwGetStartVector(IQGVertex.StartVertex)); QwasiAnalyticsData analyticsData = new QwasiAnalyticsData() { StepInterval = stepInterval, MaxStepValue = 0 }; QwasiEvaluationState currentState = new QwasiEvaluationState(__performStepOperation(stepRangeStart), stepRangeStart); analyticsData.StateEvaluationList.Add(currentState); int stepCount; for (stepCount = stepRangeStart; stepCount + stepInterval <= stepRangeEnd; stepCount += stepInterval) { currentState = new QwasiEvaluationState(__performStepOperation(stepInterval), stepCount + stepInterval); analyticsData.StateEvaluationList.Add(currentState); } analyticsData.MaxStepValue = stepCount; List <QGEdge> updatedEdges = new List <QGEdge>(); foreach (HSEdgeState edgeState in analyticsData.BasisStates) { QGEdge edge = edgeState.Vertex1.GetEdge(edgeState.Vertex2); if (updatedEdges.Contains(edge)) { continue; } this.AnalyticsEdgeLabels[edge].LoadAnalyticsData(analyticsData); updatedEdges.Add(edge); } this.CurrentAnalyticsData = analyticsData; this.RaiseAnalyticsDataCompiledEvent(new QwasiAnalyticsEventArgs(analyticsData)); return(analyticsData); }
public override IAlgebraicExpression InnerProduct(IHSExplicitVector <TBasis> other) { if (other is HSExplicitVectorValue <TBasis> v) { IList <IAlgebraicExpression> squares = new List <IAlgebraicExpression>(); foreach (var term in this) { if (v.ContainsBasisTerm(term.BasisVector)) { squares.Add(term.Coefficient.ComplexConjugate().Multiply(v[term.BasisVector])); } } return(IAlgebraicExpression.Sum(squares)); } return(IHSExplicitVector <TBasis> .InnerProductOperation(this.AsExpressionType(), other)); }