OSDN Git Service

132132
authorunknown <hskwk@.(none)>
Tue, 24 Aug 2010 03:47:41 +0000 (12:47 +0900)
committerunknown <hskwk@.(none)>
Tue, 24 Aug 2010 03:47:41 +0000 (12:47 +0900)
dev4/Pages/BinomialSolver.xaml
dev4/Pages/BinomialSolver.xaml.cs
dev4/psychlops/core/graphic/shape.cs
test4/PsychlopsMain.cs

index e08c197..c40603f 100644 (file)
@@ -3,7 +3,7 @@
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" \r
            xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"\r
            xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"\r
-           Width="400" Height="300" \r
+           Width="420" Height="300" \r
            Title="Binomial Likelihood Solver" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">\r
 \r
 \r
@@ -47,7 +47,8 @@
         </Grid.RowDefinitions>\r
 \r
                <StackPanel Orientation="Horizontal">\r
-                       <Canvas Width="250" Height="Auto">\r
+                       <Canvas Width="250" Height="Auto" x:Name="ChartCanvas">\r
+                               <TextBox x:Name="OText" Width="30" Text="{Binding Path=Value, Mode=TwoWay}" />\r
                                <toolkit:Chart x:Name="chart1" Title="" Width="240" Height="220" Canvas.Left="0" Canvas.Top="0"\r
                                                           FontSize="10">\r
                                        <toolkit:Chart.Series>\r
                                                </toolkit:ScatterSeries>\r
                                        </toolkit:Chart.Series>\r
                                </toolkit:Chart>\r
-                               <Slider x:Name="OrdinateSlider" Canvas.Left="0" Canvas.Top="10" Orientation="Vertical"  Height="200"></Slider>\r
-                               <Slider x:Name="AbscissaSlider" Canvas.Left="20" Canvas.Top="210" Width="200" MouseLeftButtonUp="AbscissaSlider_MouseLeftButtonUp"></Slider>\r
+                               <Slider x:Name="OrdinateSlider" Canvas.Left="0" Canvas.Top="10" Orientation="Vertical"  Height="200" MouseLeftButtonUp="OrdinateSlider_MouseLeftButtonUp"></Slider>\r
+                               <Slider x:Name="AbscissaSlider" Canvas.Left="20" Canvas.Top="210" Width="200"></Slider>\r
                        </Canvas>\r
 \r
 \r
-                       <StackPanel Orientation="Vertical">\r
-                               <sdk:DataGrid x:Name="dataGrid" Margin="0,5,0,10" RowHeight="40" AutoGenerateColumns="False" >\r
-                                       <sdk:DataGrid.Columns>\r
-                                               <sdk:DataGridTextColumn Header="Abscissa" Width="40" Binding="{Binding abscissa}" />\r
-                                               <sdk:DataGridTextColumn Header="Positive Cases" Width="40"  Binding="{Binding positive}" />\r
-                                               <sdk:DataGridTextColumn Header="Negative Cases" Width="40" Binding="{Binding negative}" />\r
-                                       </sdk:DataGrid.Columns>\r
-                               </sdk:DataGrid>\r
-                               <Button x:Name="AddConditionButton" Content="Add Condition" Click="AddConditionButton_Click" HorizontalAlignment="Right" FontSize="10" Margin="0,12,0,0" Grid.Row="1" />\r
-                       </StackPanel>\r
+                       <ScrollViewer>\r
+                               <StackPanel Orientation="Vertical">\r
+                                       <sdk:DataGrid x:Name="dataGrid" Margin="0,5,0,10" RowHeight="40" AutoGenerateColumns="False" >\r
+                                               <sdk:DataGrid.Columns>\r
+                                                       <sdk:DataGridTextColumn Header="Abscissa" Width="40" Binding="{Binding abscissa}" />\r
+                                                       <sdk:DataGridTextColumn Header="Positive Cases" Width="40"  Binding="{Binding positive}" />\r
+                                                       <sdk:DataGridTextColumn Header="Negative Cases" Width="40" Binding="{Binding negative}" />\r
+                                               </sdk:DataGrid.Columns>\r
+                                       </sdk:DataGrid>\r
+                                       <Button x:Name="AddConditionButton" Content="Add Condition" Click="AddConditionButton_Click" Width="100" HorizontalAlignment="Right" FontSize="10" Margin="0,12,0,0" />\r
+                                       <Button x:Name="RemoveConditionButton" Content="Remove Condition" Click="RemoveConditionButton_Click" Width="100" HorizontalAlignment="Right" FontSize="10" Margin="0,0,0,0" />\r
+                               </StackPanel>\r
+                       </ScrollViewer>\r
                </StackPanel>\r
 \r
                <TextBlock Text="Mean" x:Name="Parameter0Name" Width="40" Height="23" HorizontalAlignment="Left" Margin="0,12,0,0" Grid.Row="1" />\r
index 84c26e8..1e1eb82 100644 (file)
@@ -15,6 +15,7 @@ namespace PsychlopsSilverlight4.Pages
 {\r
        public partial class BinomialSolver : ChildWindow\r
        {\r
+               System.Windows.Shapes.Line line;\r
                int func_selected;\r
                Psychlops.Solver.Constants.Func1 func1;\r
                Psychlops.Solver.Constants.Func2 func2;\r
@@ -56,6 +57,13 @@ namespace PsychlopsSilverlight4.Pages
 \r
                        chart1.DataContext = data;\r
                        solver = new Psychlops.Solver.BinomialLikelihood();\r
+                       line = new Line();\r
+                       line.X1 = 0;\r
+                       line.Y1 = 0;\r
+                       line.X2 = ChartCanvas.ActualWidth;\r
+                       line.Y2 = 0;\r
+                       ChartCanvas.Children.Add(line);\r
+                       OText.DataContext = OrdinateSlider;\r
                }\r
                public class Data\r
                {\r
@@ -204,10 +212,55 @@ namespace PsychlopsSilverlight4.Pages
                        this.UpdateLayout();\r
                }\r
 \r
-               private void AbscissaSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)\r
+               private void RemoveConditionButton_Click(object sender, RoutedEventArgs e)\r
                {\r
-                       solver.champ[0] = AbscissaSlider.Value;\r
-                       reFunc();\r
+                       data.RemoveAt(data.Count-1);\r
+                       this.UpdateLayout();\r
+               }\r
+\r
+               private void OrdinateSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)\r
+               {\r
+                       if (solver.champ[0] == 0.0) return;\r
+                       int dir = 1, pdir, dirr=0, ii = 0;\r
+                       double d = (maximum - minimum) * 0.25;\r
+                       double refval = OrdinateSlider.Value;\r
+                       double x1 = solver.champ[0], x2= x1 + d, v1, v2, tmp;\r
+                       switch (func_selected)\r
+                       {\r
+                               case 1:\r
+                                       break;\r
+                               case 2:\r
+                                       while (dirr < 32)\r
+                                       {\r
+                                               pdir = dir;\r
+                                               v1 = Math.Abs(refval - func2(x1, solver.champ[0], solver.champ[1]));\r
+                                               v2 = Math.Abs(refval - func2(x2, solver.champ[0], solver.champ[1]));\r
+                                               if (v1 > v2)\r
+                                               {\r
+                                                       tmp = x2;\r
+                                                       x1 = x2;\r
+                                                       x2 = tmp + d;\r
+                                                       dir = 1;\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       tmp = x1;\r
+                                                       x2 = x1;\r
+                                                       x1 = tmp - d;\r
+                                                       dir = -1;\r
+                                               }\r
+                                               if (ii>32 || dir != pdir) { d /= 2; dirr++; ii = 0; }\r
+                                               ii++;\r
+                                       }\r
+                                       break;\r
+                               case 3:\r
+                                       break;\r
+                       }\r
+\r
+                       AbscissaSlider.Value = (x1+x2)/2.0;\r
+                       Parameter0.Text = AbscissaSlider.Value.ToString();\r
+                       line.Y1 = refval * 200;\r
+                       line.Y2 = refval * 200;\r
                }\r
 \r
        }\r
index 23cbeca..b007b7f 100644 (file)
@@ -70,6 +70,26 @@ namespace Psychlops{
                        set { begin = value; }\r
                }\r
 \r
+               //public static Line[] this[int x] { get { return Array(x); } }\r
+               //public static Line[,] this[int x, int y] { get { return Array(x, y); } }\r
+               public static Line[] Array(int ind)\r
+               {\r
+                       Line[] l = new Line[ind];\r
+                       for(int i=0; i<ind; i++) { l[i] = new Line(); }\r
+                       return l;\r
+               }\r
+               public static Line[,] Array(int indx, int indy)\r
+               {\r
+                       Line[,] l = new Line[indx, indy];\r
+                       for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Line(); } }\r
+                       return l;\r
+               }\r
+\r
+\r
+               public Line()\r
+               {\r
+                       set(0,0,0,0);\r
+               }\r
                public Line(double x1, double y1, double x2, double y2)\r
                {\r
                        set(x1, y1, x2, y2);\r
@@ -134,6 +154,22 @@ namespace Psychlops{
        {\r
                public Point v1, v2;\r
 \r
+               //public static Rectangle[] this[int x] { get { return Array(x); } }\r
+               //public static Rectangle[,] this[int x, int y] { get { return Array(x, y); } }\r
+               public static Rectangle[] Array(int ind)\r
+               {\r
+                       Rectangle[] l = new Rectangle[ind];\r
+                       for (int i = 0; i < ind; i++) { l[i] = new Rectangle(); }\r
+                       return l;\r
+               }\r
+               public static Rectangle[,] Array(int indx, int indy)\r
+               {\r
+                       Rectangle[,] l = new Rectangle[indx, indy];\r
+                       for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Rectangle(); } }\r
+                       return l;\r
+               }\r
+\r
+\r
                public Rectangle()\r
                {\r
                        set(0,0);\r
@@ -295,6 +331,21 @@ namespace Psychlops{
                public Point datum { get; set; }\r
                public double xdiameter, ydiameter;\r
 \r
+               //public static Ellipse[] this[int x] { get { return Array(x); } }\r
+               //public static Ellipse[,] this[int x, int y] { get { return Array(x, y); } }\r
+               public static Ellipse[] Array(int ind)\r
+               {\r
+                       Ellipse[] l = new Ellipse[ind];\r
+                       for (int i = 0; i < ind; i++) { l[i] = new Ellipse(); }\r
+                       return l;\r
+               }\r
+               public static Ellipse[,] Array(int indx, int indy)\r
+               {\r
+                       Ellipse[,] l = new Ellipse[indx, indy];\r
+                       for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Ellipse(); } }\r
+                       return l;\r
+               }\r
+\r
                public Ellipse()\r
                {\r
                        set(0,0);\r
index f5df20f..8b16867 100644 (file)
-\r
+///+ Prefix linkto BasicCode1\r
+//// Lines for set up Psychlops environment\r
 using Psychlops;\r
 \r
 namespace PsychlopsSilverlight4test\r
 {\r
 \r
        public class PsychlopsMain\r
-       {\r
+       {///- Prefix linkto BasicCode1\r
+\r
+\r
+               ///+ Main Routine\r
+               //// Psychlops runs at the first line of this function psychlops_main().\r
+               public void psychlops_main() {\r
+    ///+ 0 linkto BasicCode3_1a\r
+    ////Prepare global parameters\r
+     const int maxrectnum = 200;\r
+     int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/;\r
+     double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/;\r
+     Rectangle[] rect = Rectangle.Array(maxrectnum);\r
+     double[] rectcolorR = new double[maxrectnum];\r
+     double[] rectcolorG = new double[maxrectnum];\r
+     double[] rectcolorB = new double[maxrectnum];\r
+    ///- 0 linkto BasicCode3_1a\r
+\r
+        Canvas window = new Canvas(Canvas.window);\r
+\r
+     ///+ 1 linkto BasicCode3_1a\r
+     ////Initialize\r
+     for(int i=0; i < rectnum; i++){\r
+         ///+ 1.1 set1\r
+         ////set positions and sizes\r
+         rect[i].set(rectsize, rectsize); //Set a size of rectangles.\r
+         rect[i].centering();\r
+         rect[i].shift((i - 0.5  *rectnum) * rectsize* 1.5/*ID:RectHGap 1.0 3.0 0.5*/,\r
+                                        (i-0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions\r
+         ///- 1.1 set1\r
+         ///+ 1.2 set2\r
+         ////set colors\r
+                rectcolorR[i] = Math.random(1.0) * 0.5/*ID:RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type.\r
+                rectcolorG[i] = Math.random(1.0) * 0.5/*ID:GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type.\r
+                rectcolorB[i] = Math.random(1.0) * 0.5/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.\r
+         ///- 1.2 set2\r
+         }\r
+    ///- 1 linkto BasicCode3_1a\r
+\r
+    ///+ 2 drawing\r
+    ////drawing objects\r
+    ///+ 2.1 linkto BasicCode3_2a\r
+    ////Prepare variables for movie control;\r
+    int frame=0;\r
+    int motion_dir=1;\r
+    double Horizontal_shift, Vertical_shift;\r
+    ///- 2.1 linkto BasicCode3_2a\r
+\r
+    while(!Keyboard.esc.pushed()){\r
+        window.clear(Color.black);\r
+        for(int i=0; i < rectnum; i++){\r
+         ///+ 2.2 loopset1\r
+         ////set positions and sizes\r
+\r
+         Horizontal_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 100.0/*ID:HSpeed 0.0 100.0 10.0*/; //Calculate horizontal displacement from the center.\r
+         Vertical_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 0.0/*ID:VSpeed 0.0 100.0 10.0*/;//Calculate vertical displacement from the center.\r
+         rect[i].resize(rectsize, rectsize); //Resize rectangles.\r
+         rect[i].centering(); //Rectangles are moved to the center...\r
+         rect[i].shift(Horizontal_shift + (i-0.5*rectnum) * rectsize * 1.5/*ID:RectHGap 1.0 3.0 0.5*/,\r
+                       Vertical_shift + (i-0.5*rectnum)  *rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //and then move to designated positions\r
+         ///- 2.2 loopset1\r
+\r
+         ///+ 2.3 linkto BasicCode3_2a\r
+         ////set colors \r
+                rectcolorR[i] = Math.random(1.0) * 0.5/*ID:RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type.\r
+                rectcolorG[i] = Math.random(1.0) * 0.5/*ID:GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type.\r
+                rectcolorB[i] = Math.random(1.0) * 0.5/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.\r
+         ///- 2.3 linkto BasicCode3_2a\r
+\r
+         }\r
+               ///+ 2.4 linkto BasicCode3_1a\r
+        for(int i=0; i < rectnum; i++){\r
+            rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.\r
+        }\r
+        window.flip();\r
+               ///- 2.4 linkto BasicCode3_1a\r
+        frame++;\r
+    }\r
+    ///- 2 drawing\r
+\r
+}\r
+               ///- Main Routine\r
+\r
+\r
+\r
+       }\r
+\r
+}\r
 \r
-               Psychlops.Widgets.Slider rect_size;\r
-               Psychlops.Widgets.Slider rect_lum;\r
-               Psychlops.Widgets.Slider bg_lum;\r
 \r
 \r
+/*\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
                void RectLuminance()\r
                {\r
                        Canvas display = new Canvas(Canvas.window);\r
-                       Interval rng = new Interval();\r
-                       rect_size = new Psychlops.Widgets.Slider("Rect Size", 1 < rng < 500, 10.0);\r
-                       rect_lum = new Psychlops.Widgets.Slider("Rect Luminance", 0.0 <= rng <= 1.0, 0.1);\r
-                       bg_lum = new Psychlops.Widgets.Slider("BG Luminance", 0.0 <= rng <= 1.0, 0.1);\r
-                       Ellipse drawee = new Ellipse(100, 100);\r
-                       display.showFPS();\r
-                       display.watchFPS();\r
-\r
-                       Rectangle rect = new Rectangle(rect_size, rect_size);\r
-                       rect.centering();\r
-\r
+                       Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
+                       Letters le = new Letters("Reload to restart");\r
+                       le.fill = Color.black;\r
+                       le.align = Letters.HorizontalAlign.center;\r
 \r
-                       Clock before = new Clock(), after = new Clock();\r
                        while (!Keyboard.esc.pushed())\r
                        {\r
-                               Display.clear(bg_lum);\r
-                               rect.resize(rect_size, rect_size).draw(rect_lum);\r
-                               after.update();\r
-                               display.var((after - before).at_msec(), 100, 100, Color.green);\r
-                               display.var((after - before).at_msec(), 100, 200, Color.green);\r
-                               drawee.centering().shift(Math.random(100), 0);\r
-                               drawee.draw(Color.black);\r
+                               Display.clear(Color.white);\r
+                               le.centering().shift(-200,-10).draw();\r
                                Display.flip();\r
                        }\r
 \r
@@ -53,7 +132,7 @@ namespace PsychlopsSilverlight4test
 \r
 }\r
 \r
-\r
+*/\r
 \r
 \r
 \r