/// <summary> /// Gets the recommended sample size for the test to attain /// the power indicating in <see cref="IPowerAnalysis.Power"/> considering /// values of <see cref="IPowerAnalysis.Effect"/> and <see cref="IPowerAnalysis.Size"/>. /// </summary> /// /// <returns> /// Recommended sample size for attaining the given /// <see cref="IPowerAnalysis.Power"/> for size effect <see cref="IPowerAnalysis.Effect"/> /// under the given <see cref="IPowerAnalysis.Size"/>. /// </returns> /// public override void ComputeSamples( double proportion // = 1 ) { double Za = ZTest.PValueToStatistic(Size, Tail); double Zb = NormalDistribution.Standard .InverseDistributionFunction(Power); double n = (Za + Zb) / Effect; Samples1 = n * n; Samples2 = Samples1 * proportion; }
public void PowerTest2() { // Example from http://www.cyclismo.org/tutorial/R/power.html double mean = 6.5; double stdDev = 2; int samples = 20; double hypothesizedMean = 5; OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis; ZTest target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); IPowerAnalysis power = target.Analysis; Assert.AreEqual(0.918362, power.Power, 1e-6); }
public void EffectSizeTest2() { // Example from http://wise.cgu.edu/powermod/computing.asp double mean = 104; double stdDev = 10; int samples = 25; double hypothesizedMean = 100; OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis; ZTest target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); ZTestPowerAnalysis power = (ZTestPowerAnalysis)target.Analysis; power.Size = 0.05; power.Power = 0.80; power.ComputeEffect(); Assert.AreEqual(0.56, power.Effect, 0.001); }
public void Read(AssetReader reader) { Name = reader.ReadStringAligned(); RtBlend0.Read(reader); RtBlend1.Read(reader); RtBlend2.Read(reader); RtBlend3.Read(reader); RtBlend4.Read(reader); RtBlend5.Read(reader); RtBlend6.Read(reader); RtBlend7.Read(reader); RtSeparateBlend = reader.ReadBoolean(); reader.AlignStream(AlignType.Align4); if (IsReadZClip(reader.Version)) { ZClip.Read(reader); } ZTest.Read(reader); ZWrite.Read(reader); Culling.Read(reader); OffsetFactor.Read(reader); OffsetUnits.Read(reader); AlphaToMask.Read(reader); StencilOp.Read(reader); StencilOpFront.Read(reader); StencilOpBack.Read(reader); StencilReadMask.Read(reader); StencilWriteMask.Read(reader); StencilRef.Read(reader); FogStart.Read(reader); FogEnd.Read(reader); FogDensity.Read(reader); FogColor.Read(reader); FogMode = (FogMode)reader.ReadInt32(); GpuProgramID = reader.ReadInt32(); Tags.Read(reader); LOD = reader.ReadInt32(); Lighting = reader.ReadBoolean(); reader.AlignStream(AlignType.Align4); }
public void ZTestConstructorTest4() { // Example from http://science.kennesaw.edu/~jdemaio/1107/hypothesis_testing.htm double mean = 51.5; double stdDev = 10; int samples = 100; double hypothesizedMean = 50; // Null Hypothesis: mean = 58 // Alternative : mean != 58 OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis; ZTest target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); Assert.AreEqual(1.5, target.Statistic, 0.01); Assert.AreEqual(OneSampleHypothesis.ValueIsDifferentFromHypothesis, target.Hypothesis); Assert.AreEqual(DistributionTail.TwoTail, target.Tail); Assert.IsFalse(target.Significant); }
public void PowerTest1() { // Example from http://wise.cgu.edu/powermod/computing.asp double mean = 105; double stdDev = 10; int samples = 25; double hypothesizedMean = 100; OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsGreaterThanHypothesis; ZTest target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); var power = target.Analysis; Assert.AreEqual(0.804, power.Power, 1e-3); mean = 90; target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); power = target.Analysis; Assert.AreEqual(0.0, power.Power, 1e-3); }
public void ZTestConstructorTest3() { // Example from http://science.kennesaw.edu/~jdemaio/1107/hypothesis_testing.htm double mean = 53; double stdDev = 8; int samples = 49; double hypothesizedMean = 58; // Null Hypothesis: mean = 58 // Alternative : mean > 58 OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsGreaterThanHypothesis; ZTest target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); Assert.AreEqual(-4.38, target.Statistic, 0.01); Assert.AreEqual(OneSampleHypothesis.ValueIsGreaterThanHypothesis, target.Hypothesis); Assert.AreEqual(DistributionTail.OneUpper, target.Tail); Assert.IsFalse(target.Significant); }
public void SampleSizeTest1() { // Example from http://wise.cgu.edu/powermod/computing.asp double mean = 104; double stdDev = 10; int samples = 25; double hypothesizedMean = 100; OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsGreaterThanHypothesis; ZTest target = new ZTest(mean, stdDev, samples, hypothesizedMean, hypothesis); ZTestPowerAnalysis power = (ZTestPowerAnalysis)target.Analysis; power.Size = 0.01; power.Power = 0.90; power.ComputeSamples(); double sampleSize = System.Math.Ceiling(power.Samples); Assert.AreEqual(82, sampleSize, 1e-16); }
private void zTest(List <double> scores, double hypothesismean) { // Creates the Simple Descriptive Analysis of the given source DescriptiveAnalysis da = new DescriptiveAnalysis(scores.ToArray()); int sampleSize = scores.Count; double sampleMean = da.Means[0]; double standardDeviation = da.StandardDeviations[0]; double hypothesizedMean = hypothesismean; ZTest test = new ZTest(sampleMean, standardDeviation, sampleSize, hypothesizedMean, OneSampleHypothesis.ValueIsSmallerThanHypothesis); // Now, we can check whether this result would be // unlikely under a standard significance level: bool significant = test.Significant; // We can also check the test statistic and its P-Value double statistic = test.Statistic; double pvalue = test.PValue; }
public void Read(EndianStream stream) { Name = stream.ReadStringAligned(); RtBlend0.Read(stream); RtBlend1.Read(stream); RtBlend2.Read(stream); RtBlend3.Read(stream); RtBlend4.Read(stream); RtBlend5.Read(stream); RtBlend6.Read(stream); RtBlend7.Read(stream); RtSeparateBlend = stream.ReadBoolean(); stream.AlignStream(AlignType.Align4); ZTest.Read(stream); ZWrite.Read(stream); Culling.Read(stream); OffsetFactor.Read(stream); OffsetUnits.Read(stream); AlphaToMask.Read(stream); StencilOp.Read(stream); StencilOpFront.Read(stream); StencilOpBack.Read(stream); StencilReadMask.Read(stream); StencilWriteMask.Read(stream); StencilRef.Read(stream); FogStart.Read(stream); FogEnd.Read(stream); FogDensity.Read(stream); FogColor.Read(stream); FogMode = stream.ReadInt32(); GpuProgramID = stream.ReadInt32(); Tags.Read(stream); LOD = stream.ReadInt32(); Lighting = stream.ReadBoolean(); stream.AlignStream(AlignType.Align4); }
public static bool IsLEqual(this ZTest _this) { return(_this == ZTest.LEqual); }
public static bool IsNone(this ZTest _this) { return(_this == ZTest.None); }
public void learn_Test() { #region doc_learn_part1 // Consider the following data. An experimenter would // like to infer a relationship between two variables // A and B and a corresponding outcome variable R. double[][] example = { // A B R new double[] { 6.41, 10.11, 26.1 }, new double[] { 6.61, 22.61, 33.8 }, new double[] { 8.45, 11.11, 52.7 }, new double[] { 1.22, 18.11, 16.2 }, new double[] { 7.42, 12.81, 87.3 }, new double[] { 4.42, 10.21, 12.5 }, new double[] { 8.61, 11.94, 77.5 }, new double[] { 1.73, 13.13, 12.1 }, new double[] { 7.47, 17.11, 86.5 }, new double[] { 6.11, 15.13, 62.8 }, new double[] { 1.42, 16.11, 17.5 }, }; // For this, we first extract the input and output // pairs. The first two columns have values for the // input variables, and the last for the output: double[][] inputs = example.GetColumns(new[] { 0, 1 }); double[] output = example.GetColumn(2); // We can create a new multiple linear analysis for the variables var mlra = new MultipleLinearRegressionAnalysis(intercept: true); // Compute the analysis and obtain the estimated regression MultipleLinearRegression regression = mlra.Learn(inputs, output); #endregion // We can also show a summary ANOVA // Accord.Controls.DataGridBox.Show(regression.Table); #region doc_learn_part2 // And also extract other useful information, such // as the linear coefficients' values and std errors: double[] coef = mlra.CoefficientValues; double[] stde = mlra.StandardErrors; // Coefficients of performance, such as r² double rsquared = mlra.RSquared; // 0.62879 // Hypothesis tests for the whole model ZTest ztest = mlra.ZTest; // 0.99999 FTest ftest = mlra.FTest; // 0.01898 // and for individual coefficients TTest ttest0 = mlra.Coefficients[0].TTest; // 0.00622 TTest ttest1 = mlra.Coefficients[1].TTest; // 0.53484 // and also extract confidence intervals DoubleRange ci = mlra.Coefficients[0].Confidence; // [3.2616, 14.2193] // We can use the analysis to predict an output for a sample double y = mlra.Regression.Transform(new double[] { 10, 15 }); // We can also obtain confidence intervals for the prediction: DoubleRange pci = mlra.GetConfidenceInterval(new double[] { 10, 15 }); // and also prediction intervals for the same prediction: DoubleRange ppi = mlra.GetPredictionInterval(new double[] { 10, 15 }); #endregion Assert.AreEqual(3, coef.Length); Assert.AreEqual(8.7405051051757816, coef[0]); Assert.AreEqual(1.1198079243314365, coef[1], 1e-10); Assert.AreEqual(-19.604474518407862, coef[2], 1e-10); Assert.IsFalse(coef.HasNaN()); Assert.AreEqual(2.375916659234715, stde[0], 1e-10); Assert.AreEqual(1.7268508921418664, stde[1], 1e-10); Assert.AreEqual(30.989640986710953, stde[2], 1e-10); Assert.IsFalse(coef.HasNaN()); Assert.AreEqual(0.62879941171298936, rsquared, 1e-10); Assert.AreEqual(0.99999999999999822, ztest.PValue, 1e-10); Assert.AreEqual(0.018986050133298293, ftest.PValue, 1e-10); Assert.AreEqual(0.0062299844256985537, ttest0.PValue, 1e-10); Assert.AreEqual(0.53484850318449118, ttest1.PValue, 1e-14); Assert.IsFalse(Double.IsNaN(ttest1.PValue)); Assert.AreEqual(3.2616314640800566, ci.Min, 1e-10); Assert.AreEqual(14.219378746271506, ci.Max, 1e-10); double[][] im = mlra.InformationMatrix; double mse = regression.GetStandardError(inputs, output); DoubleRange epci = regression.GetConfidenceInterval(new double[] { 10, 15 }, mse, inputs.Length, im); Assert.AreEqual(epci.Min, pci.Min, 1e-10); Assert.AreEqual(epci.Max, pci.Max, 1e-10); Assert.AreEqual(55.27840511658215, pci.Min, 1e-10); Assert.AreEqual(113.91698568006086, pci.Max, 1e-10); Assert.AreEqual(28.783074454641557, ppi.Min, 1e-10); Assert.AreEqual(140.41231634200145, ppi.Max, 1e-10); }
//property.Expanded = EditorGUILayout.Foldout( property.Expanded, property.GetPropertyType().PropertyTypeString() ); public void Draw() { var shaderNameContent = new GUIContent( "Shader Name", "Name for shader. Includes the hierarchy listing, that is, MyShaders/Shader will be in a folder called \"MyShaders\" in the shader selection dropdown. Also used when referring to fallback shaders."); var oldColor = GUI.color; if( string.IsNullOrEmpty(_shaderName ) ) { GUI.color = Color.red; } _shaderName.Value = EditorGUILayout.TextField(shaderNameContent, _shaderName.Value); GUI.color = oldColor; var shaderFallbackContent = new GUIContent( "Shader Fallback", "Fallback shader to use in case this shader can not be used."); _shaderFallback.Value = EditorGUILayout.TextField( shaderFallbackContent, _shaderFallback.Value ); var targetContent = new GUIContent("Shader Model","Requires more recent hardware to use the shader, but allows for more instructions, texture reads, and more input information."); _shaderTarget = (ShaderTarget)EditorGUILayout.EnumPopup( targetContent, _shaderTarget ); var excludePathContent = new GUIContent("Exclude Path","Exclude a renderpath from shader generation"); _excludePath = (ExcludePath)EditorGUILayout.EnumPopup( excludePathContent, _excludePath ); GUILayout.Space(8); _showQueueSettings = EditorGUILayout.Foldout( _showQueueSettings, "Queue Settings" ); if( _showQueueSettings ) { var renderTypeContent = new GUIContent("Render Type","This is the rendertype tag inserted into the shader. Can be used for shader replace"); _renderType = (RenderType)EditorGUILayout.EnumPopup( renderTypeContent, _renderType ); if ( _renderType == RenderType.Custom ) _renderTypeCustom.Value = EditorGUILayout.TextField( "Custom Type" ,_renderTypeCustom.Value ); var queueContent = new GUIContent("Render Queue","The render queue that this material will be put in"); _queue = (Queue)EditorGUILayout.EnumPopup( queueContent, _queue ); var offContent = new GUIContent( "Queue Offset", "Offset for drawing. Used to ensure some things draw before or after others, it specifically is an offset from the given queue- That is to say, you won't have a transparent object draw before an opaque object (or similar) due to this offset."); _queueAdjust = EditorGUILayout.IntSlider(offContent, _queueAdjust.Value, -100, 100); } GUILayout.Space( 8 ); _showCullingAndDepthSettings = EditorGUILayout.Foldout( _showCullingAndDepthSettings, "Culling and Depth Settings" ); if( _showCullingAndDepthSettings ) { var zWriteContent = new GUIContent("Write Depth","Depth is considered when testing other objects. Disable for certain effects, like letting other things draw over yourself, or for speed on most overlays."); _zWrite = (ZWrite)EditorGUILayout.EnumPopup( zWriteContent, _zWrite ); var cullModeContent = new GUIContent("CullMode","Select back / forward to clip backwards facing polygons"); _cullMode = (CullMode)EditorGUILayout.EnumPopup( cullModeContent, _cullMode ); var zTestContent = new GUIContent("ZTest","Select Z-Test Value"); _zTest = (ZTest)EditorGUILayout.EnumPopup( zTestContent, _zTest ); var enableLODContent = new GUIContent("Enable LOD","Enable Shader LOD scaling"); _enableLOD = EditorGUILayout.BeginToggleGroup( enableLODContent, _enableLOD ); _lod = EditorGUILayout.IntSlider( "LOD", _lod, 0, 1000 ); EditorGUILayout.EndToggleGroup(); } GUILayout.Space( 8 ); _showBlending = EditorGUILayout.Foldout( _showBlending, "Blending Settings" ); if( _showBlending ) { var blendingTypeContent = new GUIContent("Blend Type","Use a build in blend mode or a custom blend mode"); _blending = (BlendingType)EditorGUILayout.EnumPopup( blendingTypeContent, _blending ); if( CustomBlendingEnabled() ) { var srcBlendContent = new GUIContent("Src Blend Mode","How the source channel of blending is used"); _srcBlend = (BlendingMode)EditorGUILayout.EnumPopup( srcBlendContent, _srcBlend ); var dstBlendContent = new GUIContent("Dst Blend Mode","How the destination channel of blending is used"); _dstBlend = (BlendingMode)EditorGUILayout.EnumPopup( dstBlendContent, _dstBlend ); } } GUILayout.Space( 8 ); _showColorAndLighting = EditorGUILayout.Foldout( _showColorAndLighting, "Color And Lighting Settings" ); if( _showColorAndLighting ) { GUILayout.BeginHorizontal(); GUILayout.Label( "Color Mask:", GUILayout.ExpandWidth(false) ); _colorMaskR.Value = EditorExtensions.ToggleButton( _colorMaskR.Value, "R","Mask R Channel"); _colorMaskG.Value = EditorExtensions.ToggleButton( _colorMaskG.Value, "G","Mask G Channel"); _colorMaskB.Value = EditorExtensions.ToggleButton( _colorMaskB.Value, "B","Mask B Channel"); _colorMaskA.Value = EditorExtensions.ToggleButton( _colorMaskA.Value, "A","Mask A Channel"); GUILayout.EndHorizontal(); _dualForward = GUILayout.Toggle( _dualForward, new GUIContent( "Forward Dual Lightmaps","Use dual lightmaps in the forward rendering path" )); _fullForwardShadows = GUILayout.Toggle( _fullForwardShadows, new GUIContent( "Forward Full Shadows", "Support all shadow types in Forward rendering path." )); _softVegetation = GUILayout.Toggle( _softVegetation, new GUIContent( "Soft Vegetation", "Makes the surface shader only be rendered when Soft Vegetation is on." )); _noAmbient = GUILayout.Toggle( _noAmbient, new GUIContent( "No Ambient", "Do not apply any ambient lighting or spherical harmonics lights.")); _noLightmap = GUILayout.Toggle( _noLightmap, new GUIContent( "No Lightmaps", "Disables lightmap support in this shader (makes a shader smaller)." )); _addShadow = GUILayout.Toggle( _addShadow, new GUIContent( "Advanced Shadow Pass", "Performs vertex transformations and clipping for the shadow pass, you need to use this if shadows do not display properly." )); _ignoreProjectors = GUILayout.Toggle( _ignoreProjectors, new GUIContent( "Ignore Projectors", "Ignores projector components, should be used if your doing custom vertex transformations or most transparency" )); _approxview = GUILayout.Toggle( _approxview, new GUIContent( "Approximate View", "Computes normalized view direction per-vertex instead of per-pixel, for shaders that need it. This is faster, but view direction is not entirely correct when camera gets close to surface." )); _halfasview = GUILayout.Toggle( _halfasview, new GUIContent( "Half As View", "Pass half-direction vector into the lighting function instead of view-direction. Half-direction will be computed and normalized per vertex. This is faster, but not entirely correct." )); _noForwardAdd = GUILayout.Toggle( _noForwardAdd, new GUIContent( "Disable Forward Add", "Disables Forward rendering additive pass. This makes the shader support one full directional light, with all other lights computed per-vertex/SH. Makes shaders smaller as well." )); } GUILayout.Space( 8 ); _showFogSettings = EditorGUILayout.Foldout( _showFogSettings, "Fog Settings" ); if( _showFogSettings ) { _fogModeOverride = EditorGUILayout.BeginToggleGroup( "Fog Mode Override", _fogModeOverride ); var fogModeContent = new GUIContent("Fog Mode","The type of fog to use"); _fogMode = (FogMode)EditorGUILayout.EnumPopup( fogModeContent, _fogMode ); if( _fogMode == FogMode.Linear ) { _fogNearLinear.Value = EditorGUILayout.FloatField( "Near Linear Range:", _fogNearLinear ); _fogFarLinear.Value = EditorGUILayout.FloatField( "Far Linear Range:", _fogFarLinear ); } EditorGUILayout.EndToggleGroup(); _fogColorOverride = EditorGUILayout.BeginToggleGroup( "Fog Color Override", _fogColorOverride ); _fogColor.Value = EditorGUILayout.ColorField("Fog Color:", _fogColor ); EditorGUILayout.EndToggleGroup(); _fogDensityOverride = EditorGUILayout.BeginToggleGroup( "Fog Density Override", _fogDensityOverride ); _fogDensity.Value = EditorGUILayout.FloatField( "Fog Density:", _fogDensity ); EditorGUILayout.EndToggleGroup(); } }
public static RenderStateDescriptor ZTest(ZTest value) => new RenderStateDescriptor { type = RenderStateType.ZTest, value = $"ZTest {value}" };
public void gh_937() { #region doc_learn_database // Note: this example uses a System.Data.DataTable to represent input data, // but note that this is not required. The data could have been represented // as jagged double matrices (double[][]) directly. // If you have to handle heterogeneus data in your application, such as user records // in a database, this data is best represented within the framework using a .NET's // DataTable object. In order to try to learn a classification or regression model // using this datatable, first we will need to convert the table into a representation // that the machine learning model can understand. Such representation is quite often, // a matrix of doubles (double[][]). var data = new DataTable("Customer Revenue Example"); data.Columns.Add("Day", "CustomerId", "Time (hour)", "Weather", "Revenue"); data.Rows.Add("D1", 0, 8, "Sunny", 101.2); data.Rows.Add("D2", 1, 10, "Sunny", 24.1); data.Rows.Add("D3", 2, 10, "Rain", 107); data.Rows.Add("D4", 3, 16, "Rain", 223); data.Rows.Add("D5", 4, 15, "Rain", 1); data.Rows.Add("D6", 5, 20, "Rain", 42); data.Rows.Add("D7", 6, 12, "Cloudy", 123); data.Rows.Add("D8", 7, 12, "Sunny", 64); // One way to perform this conversion is by using a Codification filter. The Codification // filter can take care of converting variables that actually denote symbols (i.e. the // weather in the example above) into representations that make more sense given the assumption // of a real vector-based classifier. // Create a codification codebook var codebook = new Codification() { { "Weather", CodificationVariable.Categorical }, { "Time (hour)", CodificationVariable.Continuous }, { "Revenue", CodificationVariable.Continuous }, }; // Learn from the data codebook.Learn(data); // Now, we will use the codebook to transform the DataTable into double[][] vectors. Due // the way the conversion works, we can end up with more columns in your output vectors // than the ones started with. If you would like more details about what those columns // represent, you can pass then as 'out' parameters in the methods that follow below. string[] inputNames; // (note: if you do not want to run this example yourself, you string outputName; // can see below the new variable names that will be generated) // Now, we can translate our training data into integer symbols using our codebook: double[][] inputs = codebook.Apply(data, "Weather", "Time (hour)").ToJagged(out inputNames); double[] outputs = codebook.Apply(data, "Revenue").ToVector(out outputName); // (note: the Apply method transform a DataTable into another DataTable containing the codified // variables. The ToJagged and ToVector methods are then used to transform those tables into // double[][] matrices and double[] vectors, respectively. // If we would like to learn a linear regression model for this data, there are two possible // ways depending on which aspect of the linear regression we are interested the most. If we // are interested in interpreting the linear regression, performing hypothesis tests with the // coefficients and performing an actual _linear regression analysis_, then we can use the // MultipleLinearRegressionAnalysis class for this. If however we are only interested in using // the learned model directly to predict new values for the dataset, then we could be using the // MultipleLinearRegression and OrdinaryLeastSquares classes directly instead. // This example deals with the former case. For the later, please see the documentation page // for the MultipleLinearRegression class. // We can create a new multiple linear analysis for the variables var mlra = new MultipleLinearRegressionAnalysis(intercept: true) { // We can also inform the names of the new variables that have been created by the // codification filter. Those can help in the visualizing the analysis once it is // data-bound to a visual control such a Windows.Forms.DataGridView or WPF DataGrid: Inputs = inputNames, // will be { "Weather: Sunny", "Weather: Rain, "Weather: Cloudy", "Time (hours)" } Output = outputName // will be "Revenue" }; // To overcome linear dependency errors mlra.OrdinaryLeastSquares.IsRobust = true; // Compute the analysis and obtain the estimated regression MultipleLinearRegression regression = mlra.Learn(inputs, outputs); // And then predict the label using double predicted = mlra.Transform(inputs[0]); // result will be ~72.3 // Because we opted for doing a MultipleLinearRegressionAnalysis instead of a simple // linear regression, we will have further information about the regression available: int inputCount = mlra.NumberOfInputs; // should be 4 int outputCount = mlra.NumberOfOutputs; // should be 1 double r2 = mlra.RSquared; // should be 0.12801838425195311 AnovaSourceCollection a = mlra.Table; // ANOVA table (bind to a visual control for quick inspection) double[][] h = mlra.InformationMatrix; // should contain Fisher's information matrix for the problem ZTest z = mlra.ZTest; // should be 0 (p=0.999, non-significant) #endregion Assert.AreEqual(72.279574468085144d, predicted, 1e-8); Assert.AreEqual(4, inputCount, 1e-8); Assert.AreEqual(1, outputCount, 1e-8); Assert.AreEqual(0.12801838425195311, r2, 1e-8); Assert.AreEqual(0.11010987669344097, a[0].Statistic, 1e-8); string str = h.ToCSharp(); double[][] expectedH = new double[][] { new double[] { 0.442293243337911, -0.069833718526197, -0.228692384542512, -0.0141758263063635, 0.143767140269202 }, new double[] { -0.0698337185261971, 0.717811616891116, -0.112258662892007, -0.0655549422852099, 0.535719235472913 }, new double[] { -0.228692384542512, -0.112258662892007, 0.717434922237013, -0.0232803210243207, 0.376483874802496 }, new double[] { -0.0141758263063635, -0.0655549422852099, -0.0232803210243207, 0.0370082984668314, -0.103011089615894 }, new double[] { 0.143767140269202, 0.535719235472913, 0.376483874802496, -0.103011089615894, 1.05597025054461 } }; Assert.IsTrue(expectedH.IsEqual(h, 1e-8)); Assert.AreEqual(0, z.Statistic, 1e-8); Assert.AreEqual(1, z.PValue, 1e-8); }
//property.Expanded = EditorGUILayout.Foldout( property.Expanded, property.GetPropertyType().PropertyTypeString() ); public void Draw() { var shaderNameContent = new GUIContent( "Shader Name", "Name for shader. Includes the hierarchy listing, that is, MyShaders/Shader will be in a folder called \"MyShaders\" in the shader selection dropdown. Also used when referring to fallback shaders."); var oldColor = GUI.color; if (string.IsNullOrEmpty(_shaderName)) { GUI.color = Color.red; } _shaderName.Value = EditorGUILayout.TextField(shaderNameContent, _shaderName.Value); GUI.color = oldColor; var shaderFallbackContent = new GUIContent( "Shader Fallback", "Fallback shader to use in case this shader can not be used."); _shaderFallback.Value = EditorGUILayout.TextField(shaderFallbackContent, _shaderFallback.Value); var targetContent = new GUIContent("Shader Model", "Requires more recent hardware to use the shader, but allows for more instructions, texture reads, and more input information."); _shaderTarget = (ShaderTarget)EditorGUILayout.EnumPopup(targetContent, _shaderTarget); var excludePathContent = new GUIContent("Exclude Path", "Exclude a renderpath from shader generation"); _excludePath = (ExcludePath)EditorGUILayout.EnumPopup(excludePathContent, _excludePath); #if UNITY_5_3_OR_NEWER var shaderTypeContent = new GUIContent("Shader Type", "You can select Physically Based Rendering after Unity 5.3"); var currentshaderType = _shaderType; _shaderType = (ShaderType)EditorGUILayout.EnumPopup(shaderTypeContent, currentshaderType); if ((currentshaderType != _shaderType) && (OnChangeShaderType != null)) { OnChangeShaderType(); } #endif GUILayout.Space(8); _showQueueSettings = EditorGUILayout.Foldout(_showQueueSettings, "Queue Settings"); if (_showQueueSettings) { var renderTypeContent = new GUIContent("Render Type", "This is the rendertype tag inserted into the shader. Can be used for shader replace"); _renderType = (RenderType)EditorGUILayout.EnumPopup(renderTypeContent, _renderType); if (_renderType == RenderType.Custom) { _renderTypeCustom.Value = EditorGUILayout.TextField("Custom Type", _renderTypeCustom.Value); } var queueContent = new GUIContent("Render Queue", "The render queue that this material will be put in"); _queue = (Queue)EditorGUILayout.EnumPopup(queueContent, _queue); var offContent = new GUIContent( "Queue Offset", "Offset for drawing. Used to ensure some things draw before or after others, it specifically is an offset from the given queue- That is to say, you won't have a transparent object draw before an opaque object (or similar) due to this offset."); _queueAdjust = EditorGUILayout.IntSlider(offContent, _queueAdjust.Value, -100, 100); } GUILayout.Space(8); _showCullingAndDepthSettings = EditorGUILayout.Foldout(_showCullingAndDepthSettings, "Culling and Depth Settings"); if (_showCullingAndDepthSettings) { var zWriteContent = new GUIContent("Write Depth", "Depth is considered when testing other objects. Disable for certain effects, like letting other things draw over yourself, or for speed on most overlays."); _zWrite = (ZWrite)EditorGUILayout.EnumPopup(zWriteContent, _zWrite); var cullModeContent = new GUIContent("CullMode", "Select back / forward to clip backwards facing polygons"); _cullMode = (CullMode)EditorGUILayout.EnumPopup(cullModeContent, _cullMode); var zTestContent = new GUIContent("ZTest", "Select Z-Test Value"); _zTest = (ZTest)EditorGUILayout.EnumPopup(zTestContent, _zTest); var enableLODContent = new GUIContent("Enable LOD", "Enable Shader LOD scaling"); _enableLOD = EditorGUILayout.BeginToggleGroup(enableLODContent, _enableLOD); _lod = EditorGUILayout.IntSlider("LOD", _lod, 0, 1000); EditorGUILayout.EndToggleGroup(); } GUILayout.Space(8); _showBlending = EditorGUILayout.Foldout(_showBlending, "Blending Settings"); if (_showBlending) { var blendingTypeContent = new GUIContent("Blend Type", "Use a build in blend mode or a custom blend mode"); _blending = (BlendingType)EditorGUILayout.EnumPopup(blendingTypeContent, _blending); if (CustomBlendingEnabled()) { var srcBlendContent = new GUIContent("Src Blend Mode", "How the source channel of blending is used"); _srcBlend = (BlendingMode)EditorGUILayout.EnumPopup(srcBlendContent, _srcBlend); var dstBlendContent = new GUIContent("Dst Blend Mode", "How the destination channel of blending is used"); _dstBlend = (BlendingMode)EditorGUILayout.EnumPopup(dstBlendContent, _dstBlend); } } GUILayout.Space(8); _showColorAndLighting = EditorGUILayout.Foldout(_showColorAndLighting, "Color And Lighting Settings"); if (_showColorAndLighting) { GUILayout.BeginHorizontal(); GUILayout.Label("Color Mask:", GUILayout.ExpandWidth(false)); _colorMaskR.Value = EditorExtensions.ToggleButton(_colorMaskR.Value, "R", "Mask R Channel"); _colorMaskG.Value = EditorExtensions.ToggleButton(_colorMaskG.Value, "G", "Mask G Channel"); _colorMaskB.Value = EditorExtensions.ToggleButton(_colorMaskB.Value, "B", "Mask B Channel"); _colorMaskA.Value = EditorExtensions.ToggleButton(_colorMaskA.Value, "A", "Mask A Channel"); GUILayout.EndHorizontal(); _dualForward = GUILayout.Toggle(_dualForward, new GUIContent("Forward Dual Lightmaps", "Use dual lightmaps in the forward rendering path")); _fullForwardShadows = GUILayout.Toggle(_fullForwardShadows, new GUIContent("Forward Full Shadows", "Support all shadow types in Forward rendering path.")); _softVegetation = GUILayout.Toggle(_softVegetation, new GUIContent("Soft Vegetation", "Makes the surface shader only be rendered when Soft Vegetation is on.")); _noAmbient = GUILayout.Toggle(_noAmbient, new GUIContent("No Ambient", "Do not apply any ambient lighting or spherical harmonics lights.")); _noLightmap = GUILayout.Toggle(_noLightmap, new GUIContent("No Lightmaps", "Disables lightmap support in this shader (makes a shader smaller).")); _addShadow = GUILayout.Toggle(_addShadow, new GUIContent("Advanced Shadow Pass", "Performs vertex transformations and clipping for the shadow pass, you need to use this if shadows do not display properly.")); _ignoreProjectors = GUILayout.Toggle(_ignoreProjectors, new GUIContent("Ignore Projectors", "Ignores projector components, should be used if your doing custom vertex transformations or most transparency")); _approxview = GUILayout.Toggle(_approxview, new GUIContent("Approximate View", "Computes normalized view direction per-vertex instead of per-pixel, for shaders that need it. This is faster, but view direction is not entirely correct when camera gets close to surface.")); _halfasview = GUILayout.Toggle(_halfasview, new GUIContent("Half As View", "Pass half-direction vector into the lighting function instead of view-direction. Half-direction will be computed and normalized per vertex. This is faster, but not entirely correct.")); _noForwardAdd = GUILayout.Toggle(_noForwardAdd, new GUIContent("Disable Forward Add", "Disables Forward rendering additive pass. This makes the shader support one full directional light, with all other lights computed per-vertex/SH. Makes shaders smaller as well.")); } GUILayout.Space(8); _showFogSettings = EditorGUILayout.Foldout(_showFogSettings, "Fog Settings"); if (_showFogSettings) { _fogModeOverride = EditorGUILayout.BeginToggleGroup("Fog Mode Override", _fogModeOverride); var fogModeContent = new GUIContent("Fog Mode", "The type of fog to use"); _fogMode = (FogMode)EditorGUILayout.EnumPopup(fogModeContent, _fogMode); if (_fogMode == FogMode.Linear) { _fogNearLinear.Value = EditorGUILayout.FloatField("Near Linear Range:", _fogNearLinear); _fogFarLinear.Value = EditorGUILayout.FloatField("Far Linear Range:", _fogFarLinear); } EditorGUILayout.EndToggleGroup(); _fogColorOverride = EditorGUILayout.BeginToggleGroup("Fog Color Override", _fogColorOverride); _fogColor.Value = EditorGUILayout.ColorField("Fog Color:", _fogColor); EditorGUILayout.EndToggleGroup(); _fogDensityOverride = EditorGUILayout.BeginToggleGroup("Fog Density Override", _fogDensityOverride); _fogDensity.Value = EditorGUILayout.FloatField("Fog Density:", _fogDensity); EditorGUILayout.EndToggleGroup(); } }
public void ComputeTest2() { // Consider the following data. An experimenter would // like to infer a relationship between two variables // A and B and a corresponding outcome variable R. double[][] example = { // A B R new double[] { 6.41, 10.11, 26.1 }, new double[] { 6.61, 22.61, 33.8 }, new double[] { 8.45, 11.11, 52.7 }, new double[] { 1.22, 18.11, 16.2 }, new double[] { 7.42, 12.81, 87.3 }, new double[] { 4.42, 10.21, 12.5 }, new double[] { 8.61, 11.94, 77.5 }, new double[] { 1.73, 13.13, 12.1 }, new double[] { 7.47, 17.11, 86.5 }, new double[] { 6.11, 15.13, 62.8 }, new double[] { 1.42, 16.11, 17.5 }, }; // For this, we first extract the input and output // pairs. The first two columns have values for the // input variables, and the last for the output: double[][] inputs = example.GetColumns(0, 1); double[] output = example.GetColumn(2); // Next, we can create a new multiple linear regression for the variables var regression = new MultipleLinearRegressionAnalysis(inputs, output, intercept: true); regression.Compute(); // compute the analysis // Now we can show a summary of analysis // Accord.Controls.DataGridBox.Show(regression.Coefficients); // We can also show a summary ANOVA // Accord.Controls.DataGridBox.Show(regression.Table); // And also extract other useful information, such // as the linear coefficients' values and std errors: double[] coef = regression.CoefficientValues; double[] stde = regression.StandardErrors; // Coefficients of performance, such as r² double rsquared = regression.RSquared; // Hypothesis tests for the whole model ZTest ztest = regression.ZTest; FTest ftest = regression.FTest; // and for individual coefficients TTest ttest0 = regression.Coefficients[0].TTest; TTest ttest1 = regression.Coefficients[1].TTest; // and also extract confidence intervals DoubleRange ci = regression.Coefficients[0].Confidence; Assert.AreEqual(3, coef.Length); Assert.AreEqual(8.7405051051757816, coef[0]); Assert.AreEqual(1.1198079243314365, coef[1], 1e-10); Assert.AreEqual(-19.604474518407862, coef[2], 1e-10); Assert.IsFalse(coef.HasNaN()); Assert.AreEqual(2.375916659234715, stde[0], 1e-10); Assert.AreEqual(1.7268508921418664, stde[1], 1e-10); Assert.AreEqual(30.989640986710953, stde[2], 1e-10); Assert.IsFalse(coef.HasNaN()); Assert.AreEqual(0.62879941171298936, rsquared); Assert.AreEqual(0.99999999999999822, ztest.PValue); Assert.AreEqual(0.018986050133298293, ftest.PValue, 1e-10); Assert.AreEqual(0.0062299844256985537, ttest0.PValue); Assert.AreEqual(0.53484850318449118, ttest1.PValue, 1e-14); Assert.IsFalse(Double.IsNaN(ttest1.PValue)); Assert.AreEqual(3.2616314640800566, ci.Min); Assert.AreEqual(14.219378746271506, ci.Max); }
/// <summary> /// Computes the Multiple Linear Regression Analysis. /// </summary> /// public void Compute() { int n = inputData.Length; int p = inputCount; SSt = SSe = outputMean = 0.0; // Compute the regression double[,] informationMatrix; regression.Regress(inputData, outputData, out informationMatrix); // Calculate mean of the expected outputs for (int i = 0; i < outputData.Length; i++) { outputMean += outputData[i]; } outputMean /= outputData.Length; // Calculate actual outputs (results) results = new double[inputData.Length]; for (int i = 0; i < inputData.Length; i++) { results[i] = regression.Compute(inputData[i]); } // Calculate SSe and SSt for (int i = 0; i < inputData.Length; i++) { double d; d = outputData[i] - results[i]; SSe += d * d; d = outputData[i] - outputMean; SSt += d * d; } // Calculate SSr SSr = SSt - SSe; // Calculate R-Squared rSquared = (SSt != 0) ? 1.0 - (SSe / SSt) : 1.0; // Calculated Adjusted R-Squared if (rSquared == 1) { rAdjusted = 1; } else { if (n - p == 1) { rAdjusted = double.NaN; } else { rAdjusted = 1.0 - (1.0 - rSquared) * ((n - 1.0) / (n - p - 1.0)); } } // Calculate Degrees of Freedom DFr = p; DFe = n - (p + 1); DFt = DFr + DFe; // Calculate Sum of Squares Mean MSe = SSe / DFe; MSr = SSr / DFr; MSt = SSt / DFt; // Calculate the F statistic ftest = new FTest(MSr / MSe, DFr, DFe); stdError = Math.Sqrt(MSe); // Create the ANOVA table List <AnovaVariationSource> table = new List <AnovaVariationSource>(); table.Add(new AnovaVariationSource(this, "Regression", SSr, DFr, MSr, ftest)); table.Add(new AnovaVariationSource(this, "Error", SSe, DFe, MSe, null)); table.Add(new AnovaVariationSource(this, "Total", SSt, DFt, MSt, null)); this.anovaTable = new AnovaSourceCollection(table); // Compute coefficient standard errors; standardErrors = new double[coefficientCount]; for (int i = 0; i < standardErrors.Length; i++) { standardErrors[i] = Math.Sqrt(MSe * informationMatrix[i, i]); } // Compute coefficient tests for (int i = 0; i < regression.Coefficients.Length; i++) { double tStatistic = regression.Coefficients[i] / standardErrors[i]; ttests[i] = new TTest(estimatedValue: regression.Coefficients[i], standardError: standardErrors[i], degreesOfFreedom: DFe); ftests[i] = new FTest(tStatistic * tStatistic, 1, DFe); confidences[i] = ttests[i].GetConfidenceInterval(confidencePercent); } // Compute model performance tests ttest = new TTest(results, outputMean); ztest = new ZTest(results, outputMean); chiSquareTest = new ChiSquareTest(outputData, results, n - p - 1); }
private void compute(double[][] x, double[] y) { int n = x.Length; int p = NumberOfInputs; SSt = 0; SSe = 0; outputMean = 0.0; NumberOfSamples = x.Length; // Compute the regression OrdinaryLeastSquares.Token = Token; regression = OrdinaryLeastSquares.Learn(x, y); informationMatrix = OrdinaryLeastSquares.GetInformationMatrix(); // Calculate mean of the expected outputs outputMean = y.Mean(); // Calculate actual outputs (results) #pragma warning disable 612, 618 results = regression.Transform(x); // Calculate SSe and SSt for (int i = 0; i < x.Length; i++) { double d; d = y[i] - results[i]; SSe += d * d; d = y[i] - outputMean; SSt += d * d; } // Calculate SSr SSr = SSt - SSe; // Calculate R-Squared rSquared = (SSt != 0) ? 1.0 - (SSe / SSt) : 1.0; // Calculated Adjusted R-Squared if (rSquared == 1) { rAdjusted = 1; } else { if (n - p == 1) { rAdjusted = double.NaN; } else { rAdjusted = 1.0 - (1.0 - rSquared) * ((n - 1.0) / (n - p - 1.0)); } } // Calculate Degrees of Freedom DFr = p; DFe = n - (p + 1); DFt = DFr + DFe; // Calculate Sum of Squares Mean MSe = SSe / DFe; MSr = SSr / DFr; MSt = SSt / DFt; // Calculate the F statistic ftest = new FTest(MSr / MSe, DFr, DFe); stdError = Math.Sqrt(MSe); // Create the ANOVA table List <AnovaVariationSource> table = new List <AnovaVariationSource>(); table.Add(new AnovaVariationSource(this, "Regression", SSr, DFr, MSr, ftest)); table.Add(new AnovaVariationSource(this, "Error", SSe, DFe, MSe, null)); table.Add(new AnovaVariationSource(this, "Total", SSt, DFt, MSt, null)); this.anovaTable = new AnovaSourceCollection(table); // Compute coefficient standard errors; standardErrors = new double[NumberOfInputs + 1]; for (int i = 0; i < informationMatrix.Length; i++) { standardErrors[i] = Math.Sqrt(MSe * informationMatrix[i][i]); } // Compute coefficient tests for (int i = 0; i < CoefficientValues.Length; i++) { double tStatistic = CoefficientValues[i] / standardErrors[i]; ttests[i] = new TTest(estimatedValue: CoefficientValues[i], standardError: standardErrors[i], degreesOfFreedom: DFe); ftests[i] = new FTest(tStatistic * tStatistic, 1, DFe); confidences[i] = ttests[i].GetConfidenceInterval(confidencePercent); } // Compute model performance tests ttest = new TTest(results, outputMean); ztest = new ZTest(results, outputMean); chiSquareTest = new ChiSquareTest(y, results, n - p - 1); #pragma warning restore 612, 618 }
public Command() // default { ZWrite = ZWrite.Off; ZTest = ZTest.LEqual; Cull = Cull.Back; // Don’t render polygons that are facing away from the viewer }