1
1
const D1 = 4 ;
2
2
const N1 = 50 ;
3
3
4
+ var load2 = document . getElementById ( "loader2" ) ;
5
+ load2 . style . fontSize = "30px" ;
6
+ load2 . style . color = "black" ;
7
+ load2 . style . fontFamily = "monospace" ;
8
+ load2 . style . backgroundColor = "greenyellow" ;
9
+
10
+ var callback2 = function ( )
11
+ {
12
+ load2 . innerHTML = "Processing...." ;
13
+ }
4
14
5
15
function render3DPrediction1 ( ctx , xs , name , proj = false ) {
6
16
let xsOriginal = xs . dataSync ( ) ;
@@ -571,83 +581,91 @@ const tensor_dataset = tf.tensor2d(iris_data, [numExamples, 5]);
571
581
572
582
573
583
574
- async function main3 ( xs ) {
575
- const xs_t = xs . gather ( [ 0 , 1 , 2 , 3 ] , 1 ) ;
584
+ function main3 ( xs ) {
576
585
586
+ return async function ( )
587
+ {
588
+ const xs_t = xs . gather ( [ 0 , 1 , 2 , 3 ] , 1 ) ;
577
589
578
- const [ axes , pcaXs ] = await pca2 ( xs , 4 ) ;
579
- xs_new = axes . concat ( xs ) ;
580
590
581
- // const div = document.getElementById('3dplot' );
582
- //render3DPrediction(div, xs_new, proj =true );
591
+ const [ axes , pcaXs ] = await pca2 ( xs , 4 ) ;
592
+ xs_new = axes . concat ( xs ) ;
583
593
584
- const ctx4 = document . getElementById ( '0-dim-iris' ) ;
585
- render1DPrediction1 ( ctx4 , xs . gather ( [ 0 ] , 1 ) , "1st Feature" ) ;
586
- const ctx5 = document . getElementById ( '1-dim-iris' ) ;
587
- render1DPrediction1 ( ctx5 , xs . gather ( [ 1 ] , 1 ) , "2nd Feature" ) ;
588
- const ctx6 = document . getElementById ( '2-dim-iris' ) ;
589
- render1DPrediction1 ( ctx6 , xs . gather ( [ 2 ] , 1 ) , "3rd Feature" ) ;
590
- const ctx11 = document . getElementById ( '3-dim-iris' ) ;
591
- render1DPrediction1 ( ctx11 , xs . gather ( [ 3 ] , 1 ) , "4th Feature" ) ;
594
+ //const div = document.getElementById('3dplot');
595
+ //render3DPrediction(div, xs_new, proj =true);
592
596
593
- console . log ( "Variance of pca" ) ;
594
- variance ( pcaXs ) ;
597
+ const ctx4 = document . getElementById ( '0-dim-iris' ) ;
598
+ render1DPrediction1 ( ctx4 , xs . gather ( [ 0 ] , 1 ) , "1st Feature" ) ;
599
+ const ctx5 = document . getElementById ( '1-dim-iris' ) ;
600
+ render1DPrediction1 ( ctx5 , xs . gather ( [ 1 ] , 1 ) , "2nd Feature" ) ;
601
+ const ctx6 = document . getElementById ( '2-dim-iris' ) ;
602
+ render1DPrediction1 ( ctx6 , xs . gather ( [ 2 ] , 1 ) , "3rd Feature" ) ;
603
+ const ctx11 = document . getElementById ( '3-dim-iris' ) ;
604
+ render1DPrediction1 ( ctx11 , xs . gather ( [ 3 ] , 1 ) , "4th Feature" ) ;
595
605
606
+ console . log ( "Variance of pca" ) ;
607
+ variance ( pcaXs ) ;
596
608
597
- yl . push ( 0 ) ;
598
609
610
+ yl . push ( 0 ) ;
599
611
600
612
601
- Plotly . newPlot ( 'var-pca' , [ {
602
- x : xl ,
603
- y : yl ,
604
- line : { simplify : false } ,
605
- } ] , { } , { showSendToCloud : true } ) ;
606
613
607
- function plot ( ) {
608
- Plotly . animate (
609
- "var-pca" , {
610
- data : [ { y : yl } ] ,
611
- traces : [ 0 ] ,
612
- layout : {
613
- autosize : true ,
614
- title : "Explained Variance" ,
615
- } ,
616
- } , {
617
- transition : {
618
- duration : 500 ,
619
- easing : "cubic-in-out" ,
620
- } ,
621
- frame : {
622
- duration : 500 ,
623
- } ,
624
- }
625
- ) ;
626
- }
627
- plot ( ) ;
614
+ Plotly . newPlot ( 'var-pca' , [ {
615
+ x : xl ,
616
+ y : yl ,
617
+ line : { simplify : false } ,
618
+ } ] , { } , { showSendToCloud : true } ) ;
619
+
620
+ function plot ( ) {
621
+ Plotly . animate (
622
+ "var-pca" , {
623
+ data : [ { y : yl } ] ,
624
+ traces : [ 0 ] ,
625
+ layout : {
626
+ autosize : true ,
627
+ title : "Explained Variance" ,
628
+ } ,
629
+ } , {
630
+ transition : {
631
+ duration : 500 ,
632
+ easing : "cubic-in-out" ,
633
+ } ,
634
+ frame : {
635
+ duration : 500 ,
636
+ } ,
637
+ }
638
+ ) ;
639
+ }
640
+ plot ( ) ;
641
+
642
+ const div2 = document . getElementById ( '3dplot-pca-iris' ) ;
643
+ render3DPrediction1 ( div2 , pcaXs . gather ( [ 0 , 1 , 2 ] , 1 ) , "3D PCA plot" ) ;
628
644
629
- const div2 = document . getElementById ( '3dplot -pca-iris' ) ;
630
- render3DPrediction1 ( div2 , pcaXs . gather ( [ 0 , 1 , 2 ] , 1 ) , "3D PCA plot " ) ;
645
+ const ctx7 = document . getElementById ( '0-dim -pca-iris' ) ;
646
+ render1DPrediction1 ( ctx7 , pcaXs . gather ( [ 0 ] , 1 ) , "1st Principal Component " ) ;
631
647
632
- const ctx7 = document . getElementById ( '0 -dim-pca-iris' ) ;
633
- render1DPrediction1 ( ctx7 , pcaXs . gather ( [ 0 ] , 1 ) , "1st Principal Component" ) ;
648
+ const ctx8 = document . getElementById ( '1 -dim-pca-iris' ) ;
649
+ render1DPrediction1 ( ctx8 , pcaXs . gather ( [ 1 ] , 1 ) , "2nd Principal Component" ) ;
634
650
635
- const ctx8 = document . getElementById ( '1 -dim-pca-iris' ) ;
636
- render1DPrediction1 ( ctx8 , pcaXs . gather ( [ 1 ] , 1 ) , "2nd Principal Component" ) ;
651
+ const ctx9 = document . getElementById ( '2 -dim-pca-iris' ) ;
652
+ render1DPrediction1 ( ctx9 , pcaXs . gather ( [ 2 ] , 1 ) , "3rd Principal Component" ) ;
637
653
638
- const ctx9 = document . getElementById ( '2 -dim-pca-iris' ) ;
639
- render1DPrediction1 ( ctx9 , pcaXs . gather ( [ 2 ] , 1 ) , "3rd Principal Component" ) ;
654
+ const ctx12 = document . getElementById ( '3 -dim-pca-iris' ) ;
655
+ render1DPrediction1 ( ctx12 , pcaXs . gather ( [ 3 ] , 1 ) , "4th Principal Component" ) ;
640
656
641
- const ctx12 = document . getElementById ( '3 -dim-pca-iris' ) ;
642
- render1DPrediction1 ( ctx12 , pcaXs . gather ( [ 3 ] , 1 ) , "4th Principal Component " ) ;
657
+ const ctx10 = document . getElementById ( '0-1 -dim-pca-iris' ) ;
658
+ render2DPrediction1 ( ctx10 , pcaXs . gather ( [ 0 , 1 ] , 1 ) , "2D PCA plot " ) ;
643
659
644
- const ctx10 = document . getElementById ( '0-1-dim-pca-iris' ) ;
645
- render2DPrediction1 ( ctx10 , pcaXs . gather ( [ 0 , 1 ] , 1 ) , "2D PCA plot" ) ;
660
+ load2 . innerHTML = "Here are your plots" + String . fromCharCode ( 0xD83D , 0xDE04 ) ;
661
+ }
646
662
}
647
663
648
664
document . getElementById ( 'Show3' )
649
665
. addEventListener ( 'click' , async ( ) => {
650
666
console . clear ( )
651
667
const xs1 = tensor_dataset . gather ( [ 0 , 1 , 2 , 3 ] , 1 ) ;
652
- main3 ( xs1 ) ;
668
+ setTimeout ( callback2 , 0 ) ;
669
+ setTimeout ( main3 ( xs1 ) , 2000 ) ;
670
+ //main3(xs1);
653
671
} ) ;
0 commit comments