当前位置: 首页>>代码示例>>C#>>正文


C# Variable类代码示例

本文整理汇总了C#中Variable的典型用法代码示例。如果您正苦于以下问题:C# Variable类的具体用法?C# Variable怎么用?C# Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Variable类属于命名空间,在下文中一共展示了Variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clone

        public void Clone()
        {
            var x = new Variable<int>("x")
                {
                    Values = {1, 2, 3},
                    Unit = new Unit("distance", "m"),
                    ExtrapolationType = ExtrapolationType.Constant,
                    InterpolationType = InterpolationType.Linear
                };

            var clone = (IVariable<int>)x.Clone();

            //Assert.IsTrue(clone.Values.SequenceEqual(new[] {1, 2, 3}));
            Assert.AreEqual(x.Name, clone.Name);
            Assert.AreNotEqual(x, clone);
            Assert.AreNotEqual(x.Store, clone.Store); // clone creates a new deep copy of the variable (in-memory)

            x.Values
                .Should("values must be copied").Have.SameSequenceAs(new[] { 1, 2, 3 });
            Assert.AreEqual(x.ExtrapolationType, clone.ExtrapolationType);
            Assert.AreEqual(x.InterpolationType, clone.InterpolationType);
            Assert.AreNotSame(x.Unit, clone.Unit);
            Assert.AreEqual(x.Unit.Name, clone.Unit.Name);
            Assert.AreEqual(x.Unit.Symbol, clone.Unit.Symbol);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:25,代码来源:VariableTest.cs

示例2: VerifyPropertiesOfVariableOfTypeShort

        public void VerifyPropertiesOfVariableOfTypeShort()
        {
            Type declaredType = typeof(short);
            Variable<short> vInt = new Variable<short>(Guid.Empty);

            Assert.Equal(declaredType, vInt.DataType);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:7,代码来源:VariableFixture.cs

示例3: Procedure

 public Procedure(string name, VariableSequence valArgs, Variable resultArg, StatementSequence statements)
 {
     AddChild(valArgs);
     AddChild(resultArg);
     AddChild(statements);
     _name = name;
 }
开发者ID:einaregilsson,项目名称:While-Language,代码行数:7,代码来源:Procedure.cs

示例4: ShouldSolveSystemWith1EquationAnd2Variables

        public void ShouldSolveSystemWith1EquationAnd2Variables()
        {
            //x+y=10    x=6; y=4
            //x-y=2
            var variableX = new Variable("x");
            var variableY = new Variable("y");

            var left1FirstEq = new Expression(1, variableX);
            var left2FirstEq = new Expression(1, variableY);
            var rightFirstEq = new Expression(10, Variable.NULL);

            var left1SecondEq = new Expression(1, variableX);
            var left2SecondEq = new Expression(-1, variableY);
            var rightSecondEq = new Expression(2, Variable.NULL);

            var firstEquation = new Equation(new List<Expression>() { left1FirstEq, left2FirstEq }, rightFirstEq);
            var secondEquation = new Equation(new List<Expression>() {left1SecondEq, left2SecondEq}, rightSecondEq);

            var target = new SystemOfEquations(new List<Equation>() {firstEquation, secondEquation});
            target.Solve();
            var resultX = variableX.Value;
            var resultY = variableY.Value;

            Assert.AreEqual(1, resultX.Count);
            Assert.AreEqual(1, resultY.Count);
            Assert.AreEqual(Variable.NULL, resultX.First().Variable);
            Assert.AreEqual(6, resultX.First().Coefficient);
            Assert.AreEqual(Variable.NULL, resultY.First().Variable);
            Assert.AreEqual(4, resultY.First().Coefficient);
        }
开发者ID:qqudesnik,项目名称:Gauss,代码行数:30,代码来源:SystemOfEquationsTests.cs

示例5: VerifyPropertiesOfVariableOfTypeBool

        public void VerifyPropertiesOfVariableOfTypeBool()
        {
            Type declaredType = typeof(bool);
            Variable<bool> vInt = new Variable<bool>(Guid.Empty);

            Assert.Equal(declaredType, vInt.DataType);
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:7,代码来源:VariableFixture.cs

示例6: Test_Double_Variable_Value_Set

 public void Test_Double_Variable_Value_Set()
 {
     Variable<double> testVar = new Variable<double>("testVar", default(double), false);
     testVar.SetValue(11.15623);
     double value = testVar.Value;
     Assert.AreEqual(11.15623, value, "Value setter does not work properly.<Double>");
 }
开发者ID:EBIA,项目名称:CompilatorScript,代码行数:7,代码来源:DoubleTests.cs

示例7: LinkVariableAction

 public LinkVariableAction(VariableInfo variableInfo, Variable linkedVariable)
 {
     VariableInfo = variableInfo;
     OldLink = variableInfo.Variable.Linked;
     OldValue = variableInfo.Value;
     NewLink = linkedVariable;
 }
开发者ID:jbatonnet,项目名称:flowtomator,代码行数:7,代码来源:LinkVariable.cs

示例8: Add

 /// <summary>
 /// Добавляет переменную в окружение
 /// </summary>
 /// <param name="var">Переменная</param>
 /// <param name="name">Имя переменной</param>
 public void Add(Variable var, string name)
 {
     EnvironsStuct es = new EnvironsStuct();
     es.name = name;
     es.value = var;
     enviroment.Add(es);
 }
开发者ID:ushim,项目名称:PascalCompile,代码行数:12,代码来源:Environment.cs

示例9: VisitCall

        /// <summary>
        /// Visits the call.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <param name="receiver">The receiver.</param>
        /// <param name="callee">The callee.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="isVirtualCall">if set to <c>true</c> [is virtual call].</param>
        /// <param name="programContext">The program context.</param>
        /// <param name="stateBeforeInstruction">The state before instruction.</param>
        /// <param name="stateAfterInstruction">The state after instruction.</param>
        public override void VisitCall(
            Variable destination, 
            Variable receiver, 
            Method callee, 
            ExpressionList arguments, 
            bool isVirtualCall, 
            Microsoft.Fugue.IProgramContext programContext, 
            Microsoft.Fugue.IExecutionState stateBeforeInstruction, 
            Microsoft.Fugue.IExecutionState stateAfterInstruction)
        {
            if ((callee.DeclaringType.GetRuntimeType() == typeof(X509ServiceCertificateAuthentication) ||
                 callee.DeclaringType.GetRuntimeType() == typeof(X509ClientCertificateAuthentication)) &&
                 (callee.Name.Name.Equals("set_CertificateValidationMode", StringComparison.InvariantCultureIgnoreCase)))
            {
                IAbstractValue value = stateBeforeInstruction.Lookup((Variable)arguments[0]);
                IIntValue intValue = value.IntValue(stateBeforeInstruction);

                if (intValue != null)
                {
                    X509CertificateValidationMode mode = (X509CertificateValidationMode)intValue.Value;
                    if (mode != X509CertificateValidationMode.ChainTrust)
                    {
                        Resolution resolution = base.GetResolution(mode.ToString(), 
                            X509CertificateValidationMode.ChainTrust.ToString());
                        Problem problem = new Problem(resolution, programContext);
                        base.Problems.Add(problem);
                    }
                }
            }

            base.VisitCall(destination, receiver, callee, arguments, isVirtualCall, programContext, stateBeforeInstruction, stateAfterInstruction);
        }
开发者ID:Phidiax,项目名称:open-wssf-2015,代码行数:43,代码来源:CertificateValidationMode.cs

示例10: UpdateHelper

        private double UpdateHelper(Message<GaussianDistribution> message1, Message<GaussianDistribution> message2,
            Variable<GaussianDistribution> variable1, Variable<GaussianDistribution> variable2)
        {
            GaussianDistribution message1Value = message1.Value.Clone();
            GaussianDistribution message2Value = message2.Value.Clone();

            GaussianDistribution marginal1 = variable1.Value.Clone();
            GaussianDistribution marginal2 = variable2.Value.Clone();

            double a = _Precision/(_Precision + marginal2.Precision - message2Value.Precision);

            GaussianDistribution newMessage = GaussianDistribution.FromPrecisionMean(
                a*(marginal2.PrecisionMean - message2Value.PrecisionMean),
                a*(marginal2.Precision - message2Value.Precision));

            GaussianDistribution oldMarginalWithoutMessage = marginal1/message1Value;

            GaussianDistribution newMarginal = oldMarginalWithoutMessage*newMessage;

            /// Update the message and marginal

            message1.Value = newMessage;
            variable1.Value = newMarginal;

            /// Return the difference in the new marginal
            return newMarginal - marginal1;
        }
开发者ID:vmendi,项目名称:UnusualEngine,代码行数:27,代码来源:GaussianLikelihoodFactor.cs

示例11: TestAsArgument

        public void TestAsArgument()
        {
            IVariable<IFeatureLocation> a = new Variable<IFeatureLocation>("argument");
            IVariable<double> c1 = new Variable<double>("value");
            IVariable<string> c2 = new Variable<string>("description");

            // f = (a, p)(h)
            IFunction f = new Function("rating curve");
            f.Arguments.Add(a);
            f.Components.Add(c1);
            f.Components.Add(c2);

            SimpleFeature simpleFeature = new SimpleFeature(10.0);
            IFeatureLocation featureLocation = new FeatureLocation { Feature = simpleFeature };

            // value based argument referencing.
            f[featureLocation] = new object[] { 1.0, "jemig de pemig" };

            IMultiDimensionalArray<double> c1Value = f.GetValues<double>(new ComponentFilter(f.Components[0]),
                                                                         new VariableValueFilter<IFeatureLocation>(
                                                                             f.Arguments[0],
                                                                             new FeatureLocation
                                                                                 {Feature = simpleFeature}));

            Assert.AreEqual(1.0, c1Value[0], 1.0e-6);

            //IMultiDimensionalArray<string> c2Value = f.GetValues<string>(new ComponentFilter(f.Components[1]),
            //                                                             new VariableValueFilter<IFeatureLocation>(
            //                                                                 f.Arguments[0], featureLocation));

            //Assert.AreEqual("jemig de pemig", c2Value[0]);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:32,代码来源:FeatureLocationTest.cs

示例12: TryGetMember

 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     try
     {
         Variable variable;
         if(!variables.TryGetValue(binder.Name, out variable))
         {
             int idx = GetGlobalVarIndexByName(binder.Name);
             var ptr = GetAddressOfGlobalVar(idx);
             if(ptr == IntPtr.Zero)
             {
                 result = null;
                 return true;
             }
             int tid;
             GetGlobalVar(idx, out tid);
             var instance = ScriptEngine.GetVariable(ptr, tid);
             variables[binder.Name] = variable = new Variable(instance, ptr, tid);
         }
         result = ScriptEngine.GetVariable(variable.Address, variable.TypeId, variable.Instance);
         return true;
     }
     catch(Exception ex)
     {
         ScriptEngine.Log ("Exception caught while fetching '{0}' variable of module '{1}': {2}.", binder.Name, Name, ex.Message);
         result = null;
         return false;
     }
 }
开发者ID:wladimiiir,项目名称:vault112,代码行数:29,代码来源:ScriptModule.cs

示例13: Window1

		public Window1()
		{
			InitializeComponent();

			//------------------------
			// The model
			//------------------------
			// c represents the position of the car
			c = Variable.DiscreteUniform(3).Named("Car");
			// p represents the pick. This will be observed
			p = Variable.DiscreteUniform(3).Named("Pick");
			// h represents the host pick.
			h = Variable.New<int>().Named("Host");
			// Whether the host is observed
			hostIsObserved = Variable.Observed<bool>(false);

			for (int a = 0; a < 3; a++) for (int b = 0; b < 3; b++)
				{
					double[] probs = { 1, 1, 1 };
					for (int ps = 0; ps < 3; ps++) if (ps == a || ps == b) probs[ps] = 0;
					using (Variable.Case(p, a)) using (Variable.Case(c, b)) h.SetTo(Variable.Discrete(probs));
				}
			using (Variable.If(hostIsObserved))
				Variable.ConstrainFalse(h == c);

			// Compile the model
			getProbs(h);

			OnReset();
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:30,代码来源:Window1.xaml.cs

示例14: ComputeAndConstrainScores

        /// <summary>
        /// Compute score for vectors, and constrain the score require to be the maximum 
        /// for the class inferred in model results
        /// </summary>
        protected void ComputeAndConstrainScores(Variable<Vector>[] variableVector)
        {
            using (Variable.ForEach(this.range))
            {
                var score = new Variable<double>[numOfClasses];
                var scorePlusNoise = new Variable<double>[numOfClasses];

                for (int i = 0; i < numOfClasses; i++)
                {
                    score[i] = Variable.InnerProduct(variableVector[i], this.featureVectors[this.range]);
                    scorePlusNoise[i] = Variable.GaussianFromMeanAndPrecision(score[i], Noise);
                }

                this.modelOutput[this.range] = Variable.DiscreteUniform(numOfClasses);

                for (int j = 0; j < numOfClasses; j++)
                {
                    using (Variable.Case(this.modelOutput[this.range], j))
                    {
                        for (int k = 0; k < scorePlusNoise.Length; k++)
                        {
                            if (k != j)
                            {
                                Variable.ConstrainPositive(scorePlusNoise[j] - scorePlusNoise[k]);
                            }
                        }
                    }
                }
            }
        }
开发者ID:yoroto,项目名称:BayesPointMachines,代码行数:34,代码来源:VectorsTestModel.cs

示例15: HandleFailure

 private void HandleFailure(Variable failure)
 {
     var defaultPair = DefaultPrivacyProvider.DefaultPair;
     var time = Group.EngineTimeData;
     Response = new ReportMessage(
         Request.Version,
         new Header(
             new Integer32(Request.MessageId()),
             new Integer32(Messenger.MaxMessageSize),
             0), // no need to encrypt.
         new SecurityParameters(
             Group.EngineId,
             new Integer32(time[0]),
             new Integer32(time[1]),
             Request.Parameters.UserName,
             defaultPair.AuthenticationProvider.CleanDigest,
             defaultPair.Salt),
         new Scope(
             Group.EngineId,
             OctetString.Empty,
             new ReportPdu(
                 Request.RequestId(),
                 ErrorCode.NoError,
                 0,
                 new List<Variable>(1) { failure })),
         defaultPair,
         null);
     if (TooBig)
     {
         GenerateTooBig();
     }
 }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:32,代码来源:SecureSnmpContext.cs


注:本文中的Variable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。