Spaces:
Running
Running
File size: 123,215 Bytes
65dac5d 6536b45 65dac5d 6536b45 14422b0 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 745192b 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 87f43b1 65dac5d 6536b45 65dac5d 6536b45 87f43b1 7e9fb6b 6536b45 7e9fb6b 6536b45 7e9fb6b 65dac5d 2da7131 87f43b1 65dac5d 87f43b1 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 14422b0 6536b45 65dac5d 6536b45 65dac5d 6536b45 14422b0 745192b 87f43b1 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 6536b45 745192b 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 14422b0 65dac5d 6536b45 65dac5d 6536b45 14422b0 65dac5d 6536b45 65dac5d 14422b0 6536b45 65dac5d 14422b0 6536b45 14422b0 6536b45 14422b0 6536b45 14422b0 6536b45 14422b0 6536b45 14422b0 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 6536b45 87f43b1 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 65dac5d 6536b45 745192b 14422b0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 |
// ===== CONFIGURATION & CONSTANTS =====
const COLORS = {
primary: '#4a90e2',
cyan: '#64ffda',
orange: '#ff6b6b',
green: '#51cf66',
background: '#0f3460',
text: '#e1e1e1',
textSecondary: '#a0a0a0'
};
const chartColors = ['#1FB8CD', '#FFC185', '#B4413C', '#ECEBD5', '#5D878F', '#DB4545', '#D2BA4C', '#964325', '#944454', '#13343B'];
// ===== STATE MANAGEMENT =====
let currentTopic = 1;
let currentSubject = 'statistics';
let animationFrames = {};
// ===== INITIALIZATION =====
document.addEventListener('DOMContentLoaded', () => {
// Core initialization
initNavigation();
initSubjectTabs();
initInteractiveElements();
setupScrollObserver();
initializeAllVisualizations();
// Enhanced features
initSearch();
initProgressTracking();
initKeyboardShortcuts();
initLazyLoading();
// Fix Show Answer buttons (Remove inline handlers to avoid conflicts)
document.querySelectorAll('.show-answers-btn, .show-answer-btn').forEach(btn => {
btn.removeAttribute('onclick');
});
// Show initial subject
switchSubject('statistics');
// Log features
console.log('%c🚀 Enhanced Features Active:', 'color: #64ffda; font-size: 14px; font-weight: bold;');
console.log('%c ✓ Global Search (Ctrl/Cmd+K)', 'color: #4a90e2;');
console.log('%c ✓ Progress Tracking (saved locally)', 'color: #4a90e2;');
console.log('%c ✓ MathJax Formula Rendering', 'color: #4a90e2;');
console.log('%c ✓ Keyboard Navigation (Alt+↑/↓)', 'color: #4a90e2;');
});
// ===== SUBJECT SWITCHING =====
function initSubjectTabs() {
const tabs = document.querySelectorAll('.subject-tab');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
const subject = tab.dataset.subject;
switchSubject(subject);
});
});
}
function switchSubject(subject) {
currentSubject = subject;
// Update active tab
document.querySelectorAll('.subject-tab').forEach(tab => {
tab.classList.remove('active');
if (tab.dataset.subject === subject) {
tab.classList.add('active');
}
});
// Update sidebar title
const titles = {
'statistics': 'Statistics Content',
'linear-algebra': 'Linear Algebra Content',
'calculus': 'Calculus Content',
'data-science': 'Data Science Content',
'machine-learning': 'Machine Learning Algorithms'
};
const sidebarTitle = document.getElementById('sidebarTitle');
if (sidebarTitle) {
sidebarTitle.textContent = titles[subject];
}
// Show/hide sidebar modules
document.querySelectorAll('.module').forEach(module => {
const moduleSubject = module.dataset.subject;
if (moduleSubject) {
module.style.display = moduleSubject === subject ? 'block' : 'none';
} else {
// Statistics modules (no data-subject attribute)
module.style.display = subject === 'statistics' ? 'block' : 'none';
}
});
// Show/hide topic sections
document.querySelectorAll('.topic-section').forEach(section => {
const sectionSubject = section.dataset.subject || 'statistics';
section.style.display = sectionSubject === subject ? 'block' : 'none';
});
// Scroll to first topic of subject
const firstTopic = document.querySelector(`.topic-section[data-subject="${subject}"], .topic-section:not([data-subject])`);
if (firstTopic && subject !== 'statistics') {
setTimeout(() => {
firstTopic.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 100);
} else if (subject === 'statistics') {
const statsFirst = document.getElementById('topic-1');
if (statsFirst) {
setTimeout(() => {
statsFirst.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 100);
}
}
}
// ===== NAVIGATION =====
function initNavigation() {
// Mobile menu toggle
const mobileMenuBtn = document.getElementById('mobileMenuBtn');
const sidebar = document.getElementById('sidebar');
if (mobileMenuBtn) {
mobileMenuBtn.addEventListener('click', () => {
sidebar.classList.toggle('active');
});
}
// Topic link navigation
const topicLinks = document.querySelectorAll('.topic-link');
topicLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const topicId = link.getAttribute('data-topic');
// Handle both 'topic-X' and 'ml-topic-X' formats
let target = document.getElementById(topicId);
if (!target && !topicId.includes('-')) {
target = document.getElementById(`topic-${topicId}`);
}
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
updateActiveLink(topicId);
// Close mobile menu if open
if (window.innerWidth <= 1024) {
sidebar.classList.remove('active');
}
}
});
});
}
function updateActiveLink(topicId) {
document.querySelectorAll('.topic-link').forEach(link => {
link.classList.remove('active');
});
const activeLink = document.querySelector(`[data-topic="${topicId}"]`);
if (activeLink) {
activeLink.classList.add('active');
}
currentTopic = parseInt(topicId);
}
// ===== SCROLL OBSERVER =====
function setupScrollObserver() {
const options = {
root: null,
rootMargin: '-100px',
threshold: 0.3
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Handle both 'topic-X' and 'ml-topic-X' formats
const fullId = entry.target.id;
updateActiveLink(fullId);
}
});
}, options);
document.querySelectorAll('.topic-section').forEach(section => {
observer.observe(section);
});
}
// ===== CANVAS UTILITIES =====
function clearCanvas(ctx, canvas) {
ctx.fillStyle = COLORS.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
function drawText(ctx, text, x, y, fontSize = 14, color = COLORS.text, align = 'center') {
ctx.fillStyle = color;
ctx.font = `${fontSize}px 'Segoe UI', sans-serif`;
ctx.textAlign = align;
ctx.fillText(text, x, y);
}
function drawCircle(ctx, x, y, radius, color, filled = true) {
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2);
if (filled) {
ctx.fillStyle = color;
ctx.fill();
} else {
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.stroke();
}
}
function drawLine(ctx, x1, y1, x2, y2, color = COLORS.text, width = 1) {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.strokeStyle = color;
ctx.lineWidth = width;
ctx.stroke();
}
function drawRect(ctx, x, y, width, height, color, filled = true) {
if (filled) {
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
} else {
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.strokeRect(x, y, width, height);
}
}
// ===== STATISTICAL CALCULATIONS =====
function calculateMean(data) {
return data.reduce((sum, val) => sum + val, 0) / data.length;
}
function calculateMedian(data) {
const sorted = [...data].sort((a, b) => a - b);
const mid = Math.floor(sorted.length / 2);
return sorted.length % 2 === 0
? (sorted[mid - 1] + sorted[mid]) / 2
: sorted[mid];
}
function calculateMode(data) {
const frequency = {};
let maxFreq = 0;
data.forEach(val => {
frequency[val] = (frequency[val] || 0) + 1;
maxFreq = Math.max(maxFreq, frequency[val]);
});
if (maxFreq === 1) return 'None';
const modes = Object.keys(frequency).filter(key => frequency[key] === maxFreq);
return modes.join(', ');
}
function calculateVariance(data, isSample = true) {
const mean = calculateMean(data);
const squaredDiffs = data.map(val => Math.pow(val - mean, 2));
const divisor = isSample ? data.length - 1 : data.length;
return squaredDiffs.reduce((sum, val) => sum + val, 0) / divisor;
}
function calculateStdDev(data, isSample = true) {
return Math.sqrt(calculateVariance(data, isSample));
}
function calculateQuartiles(data) {
const sorted = [...data].sort((a, b) => a - b);
const q2 = calculateMedian(sorted);
const midIndex = Math.floor(sorted.length / 2);
const lowerHalf = sorted.length % 2 === 0
? sorted.slice(0, midIndex)
: sorted.slice(0, midIndex);
const upperHalf = sorted.length % 2 === 0
? sorted.slice(midIndex)
: sorted.slice(midIndex + 1);
const q1 = calculateMedian(lowerHalf);
const q3 = calculateMedian(upperHalf);
return { q1, q2, q3 };
}
function calculateIQR(data) {
const { q1, q3 } = calculateQuartiles(data);
const iqr = q3 - q1;
const lowerFence = q1 - 1.5 * iqr;
const upperFence = q3 + 1.5 * iqr;
return { q1, q3, iqr, lowerFence, upperFence };
}
function detectOutliers(data) {
const { lowerFence, upperFence } = calculateIQR(data);
return data.filter(val => val < lowerFence || val > upperFence);
}
function calculateCovariance(x, y) {
const meanX = calculateMean(x);
const meanY = calculateMean(y);
let sum = 0;
for (let i = 0; i < x.length; i++) {
sum += (x[i] - meanX) * (y[i] - meanY);
}
return sum / (x.length - 1);
}
function calculateCorrelation(x, y) {
const cov = calculateCovariance(x, y);
const stdX = calculateStdDev(x);
const stdY = calculateStdDev(y);
return cov / (stdX * stdY);
}
// ===== VISUALIZATION FUNCTIONS =====
// Population vs Sample Visualization
function initPopulationSampleViz() {
const canvas = document.getElementById('populationSampleCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let population = [];
let sample = [];
let sampleSize = 30;
// Initialize population
for (let i = 0; i < 200; i++) {
population.push({
x: Math.random() * (canvas.width - 40) + 20,
y: Math.random() * (canvas.height - 40) + 20,
inSample: false
});
}
function draw() {
clearCanvas(ctx, canvas);
// Draw title
drawText(ctx, 'Population (All dots) vs Sample (Highlighted)', canvas.width / 2, 30, 16, COLORS.cyan);
// Draw population
population.forEach(point => {
const color = point.inSample ? COLORS.orange : COLORS.primary;
const radius = point.inSample ? 6 : 4;
drawCircle(ctx, point.x, point.y, radius, color);
});
// Draw statistics
const popCount = population.length;
const sampleCount = population.filter(p => p.inSample).length;
drawText(ctx, `Population Size: N = ${popCount}`, 150, canvas.height - 20, 14, COLORS.text, 'center');
drawText(ctx, `Sample Size: n = ${sampleCount}`, canvas.width - 150, canvas.height - 20, 14, COLORS.orange, 'center');
}
function takeSample() {
// Reset all
population.forEach(p => p.inSample = false);
// Randomly select sample
const shuffled = [...population].sort(() => Math.random() - 0.5);
for (let i = 0; i < Math.min(sampleSize, population.length); i++) {
shuffled[i].inSample = true;
}
draw();
}
// Event listeners
const sampleBtn = document.getElementById('sampleBtn');
const resetBtn = document.getElementById('resetPopBtn');
const sizeSlider = document.getElementById('sampleSizeSlider');
const sizeLabel = document.getElementById('sampleSizeLabel');
if (sampleBtn) {
sampleBtn.addEventListener('click', takeSample);
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
population.forEach(p => p.inSample = false);
draw();
});
}
if (sizeSlider) {
sizeSlider.addEventListener('input', (e) => {
sampleSize = parseInt(e.target.value);
if (sizeLabel) {
sizeLabel.textContent = sampleSize;
}
});
}
draw();
}
// Central Tendency Visualization
function initCentralTendencyViz() {
const canvas = document.getElementById('centralTendencyCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let data = [10, 20, 30, 40, 50];
function parseInput(input) {
return input.split(',').map(s => parseFloat(s.trim())).filter(n => !isNaN(n));
}
function draw() {
clearCanvas(ctx, canvas);
if (data.length === 0) {
drawText(ctx, 'Please enter valid numbers', canvas.width / 2, canvas.height / 2, 16, COLORS.orange);
return;
}
const sorted = [...data].sort((a, b) => a - b);
const min = Math.min(...sorted);
const max = Math.max(...sorted);
const range = max - min || 1;
const padding = 80;
const width = canvas.width - 2 * padding;
// Calculate statistics
const mean = calculateMean(data);
const median = calculateMedian(data);
const mode = calculateMode(data);
// Update results display
document.getElementById('meanResult').textContent = mean.toFixed(2);
document.getElementById('medianResult').textContent = median.toFixed(2);
document.getElementById('modeResult').textContent = mode;
// Draw axis
const axisY = canvas.height / 2;
drawLine(ctx, padding, axisY, canvas.width - padding, axisY, COLORS.text, 2);
// Draw data points
sorted.forEach((val, idx) => {
const x = padding + ((val - min) / range) * width;
drawCircle(ctx, x, axisY, 8, COLORS.primary);
drawText(ctx, val.toString(), x, axisY + 30, 12, COLORS.text);
});
// Draw mean
const meanX = padding + ((mean - min) / range) * width;
drawLine(ctx, meanX, axisY - 60, meanX, axisY + 60, COLORS.cyan, 3);
drawText(ctx, `Mean: ${mean.toFixed(2)}`, meanX, axisY - 70, 14, COLORS.cyan);
// Draw median
const medianX = padding + ((median - min) / range) * width;
drawLine(ctx, medianX, axisY - 50, medianX, axisY + 50, COLORS.orange, 2);
drawText(ctx, `Median: ${median.toFixed(2)}`, medianX, axisY - 55, 12, COLORS.orange);
}
// Event listeners
const input = document.getElementById('centralTendencyInput');
const calcBtn = document.getElementById('calculateCentralBtn');
const randomBtn = document.getElementById('randomDataBtn');
if (calcBtn && input) {
calcBtn.addEventListener('click', () => {
data = parseInput(input.value);
draw();
});
}
if (randomBtn && input) {
randomBtn.addEventListener('click', () => {
data = Array.from({ length: 10 }, () => Math.floor(Math.random() * 100));
input.value = data.join(', ');
draw();
});
}
if (input) {
input.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
data = parseInput(input.value);
draw();
}
});
}
draw();
}
// ===== INITIALIZE ALL VISUALIZATIONS =====
function initializeAllVisualizations() {
// Statistics visualizations
initPopulationSampleViz();
initCentralTendencyViz();
// Linear Algebra visualizations
initVectorCanvas();
initSpanCanvas();
initTransformationGrid();
initEigenvectorCanvas(); // This now calls the updated version
// Advanced Stats (New)
initSkewnessVisualization();
initCovarianceVisualization();
initPDFCDFVisualization();
initNormalRuleVisualization();
initCorrelationVisualization();
// Calculus visualizations
initCircleAreaCanvas();
initDerivativeCanvas();
initRiemannSumCanvas();
initTaylorSeriesCanvas();
// Data Science visualizations
initSimpleRegressionCanvas();
initLogisticRegressionCanvas();
initPolynomialRegressionCanvas();
initPCACanvas();
initGradientDescentCanvas();
initLossLandscapeCanvas();
// Machine Learning (New)
initDecisionTreeVisualization();
// Machine Learning visualizations
initMLLinearRegressionCanvas();
initMLKMeansCanvas();
initMLSVMCanvas();
initMLRandomForestCanvas();
initMLGradientBoostingCanvas();
initMLNeuralNetworkCanvas();
}
// ===== MACHINE LEARNING VISUALIZATIONS =====
function initMLLinearRegressionCanvas() {
const canvas = document.getElementById('canvas-ml-1');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let showLine = false;
// House price data from worked example
const data = [
{ x: 1000, y: 150 },
{ x: 1500, y: 200 },
{ x: 2000, y: 250 },
{ x: 3000, y: 350 }
];
function draw() {
clearCanvas(ctx, canvas);
const padding = 80;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const maxX = 3500;
const maxY = 400;
// Draw axes
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, canvas.height - padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, canvas.height - padding, COLORS.text, 2);
// Draw grid
for (let i = 0; i <= 7; i++) {
const x = padding + (i / 7) * width;
const xVal = (i * 500).toString();
drawLine(ctx, x, canvas.height - padding, x, canvas.height - padding + 5, COLORS.textSecondary, 1);
drawText(ctx, xVal, x, canvas.height - padding + 20, 10, COLORS.textSecondary);
}
for (let i = 0; i <= 8; i++) {
const y = canvas.height - padding - (i / 8) * height;
const yVal = (i * 50).toString();
drawLine(ctx, padding - 5, y, padding, y, COLORS.textSecondary, 1);
drawText(ctx, yVal, padding - 15, y + 4, 10, COLORS.textSecondary, 'right');
}
// Draw labels
drawText(ctx, 'Size (sq ft)', canvas.width / 2, canvas.height - 10, 12, COLORS.cyan);
ctx.save();
ctx.translate(20, canvas.height / 2);
ctx.rotate(-Math.PI / 2);
drawText(ctx, 'Price ($1000s)', 0, 0, 12, COLORS.cyan);
ctx.restore();
// Draw data points
data.forEach(point => {
const px = padding + (point.x / maxX) * width;
const py = canvas.height - padding - (point.y / maxY) * height;
drawCircle(ctx, px, py, 8, COLORS.cyan);
drawText(ctx, `${point.y}k`, px + 15, py - 10, 10, COLORS.cyan, 'left');
});
// Draw regression line if enabled
if (showLine) {
// From worked example: y = 50 + 0.1x
const slope = 0.1;
const intercept = 50;
const x1 = 0;
const y1 = intercept;
const x2 = maxX;
const y2 = intercept + slope * x2;
const px1 = padding + (x1 / maxX) * width;
const py1 = canvas.height - padding - (y1 / maxY) * height;
const px2 = padding + (x2 / maxX) * width;
const py2 = canvas.height - padding - (y2 / maxY) * height;
drawLine(ctx, px1, py1, px2, py2, COLORS.orange, 3);
// Show equation
drawText(ctx, 'y = 50 + 0.10x', canvas.width / 2, 30, 16, COLORS.orange);
drawText(ctx, 'R² = 1.00 (Perfect Fit!)', canvas.width / 2, 50, 14, COLORS.green);
// Highlight prediction point (2500, 300)
const predX = 2500;
const predY = 50 + 0.1 * predX;
const ppx = padding + (predX / maxX) * width;
const ppy = canvas.height - padding - (predY / maxY) * height;
drawCircle(ctx, ppx, ppy, 10, COLORS.green);
drawText(ctx, '2500 sq ft → $300k', ppx - 80, ppy - 15, 12, COLORS.green, 'left');
}
}
const fitBtn = document.getElementById('btn-ml-1-fit');
const resetBtn = document.getElementById('btn-ml-1-reset');
if (fitBtn) {
fitBtn.addEventListener('click', () => {
showLine = true;
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
showLine = false;
draw();
});
}
draw();
}
function initMLKMeansCanvas() {
const canvas = document.getElementById('canvas-ml-15');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let clustered = false;
// Customer data from worked example
const customers = [
{ name: 'A', age: 25, income: 40, cluster: null },
{ name: 'B', age: 30, income: 50, cluster: null },
{ name: 'C', age: 28, income: 45, cluster: null },
{ name: 'D', age: 55, income: 80, cluster: null },
{ name: 'E', age: 60, income: 90, cluster: null },
{ name: 'F', age: 52, income: 75, cluster: null }
];
let centroids = [
{ age: 25, income: 40, color: COLORS.cyan },
{ age: 60, income: 90, color: COLORS.orange }
];
function assignClusters() {
customers.forEach(customer => {
// Calculate distance to each centroid
const d1 = Math.sqrt(Math.pow(customer.age - centroids[0].age, 2) + Math.pow(customer.income - centroids[0].income, 2));
const d2 = Math.sqrt(Math.pow(customer.age - centroids[1].age, 2) + Math.pow(customer.income - centroids[1].income, 2));
customer.cluster = d1 < d2 ? 0 : 1;
});
// Update centroids
const cluster0 = customers.filter(c => c.cluster === 0);
const cluster1 = customers.filter(c => c.cluster === 1);
if (cluster0.length > 0) {
centroids[0].age = cluster0.reduce((s, c) => s + c.age, 0) / cluster0.length;
centroids[0].income = cluster0.reduce((s, c) => s + c.income, 0) / cluster0.length;
}
if (cluster1.length > 0) {
centroids[1].age = cluster1.reduce((s, c) => s + c.age, 0) / cluster1.length;
centroids[1].income = cluster1.reduce((s, c) => s + c.income, 0) / cluster1.length;
}
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 80;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const minAge = 20, maxAge = 70;
const minIncome = 30, maxIncome = 100;
// Draw axes
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, canvas.height - padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, canvas.height - padding, COLORS.text, 2);
// Draw grid
for (let age = 20; age <= 70; age += 10) {
const x = padding + ((age - minAge) / (maxAge - minAge)) * width;
drawLine(ctx, x, canvas.height - padding, x, canvas.height - padding + 5, COLORS.textSecondary, 1);
drawText(ctx, age.toString(), x, canvas.height - padding + 20, 10, COLORS.textSecondary);
}
for (let income = 30; income <= 100; income += 10) {
const y = canvas.height - padding - ((income - minIncome) / (maxIncome - minIncome)) * height;
drawLine(ctx, padding - 5, y, padding, y, COLORS.textSecondary, 1);
drawText(ctx, `$${income}k`, padding - 40, y + 4, 10, COLORS.textSecondary, 'right');
}
// Draw labels
drawText(ctx, 'Age', canvas.width / 2, canvas.height - 10, 12, COLORS.cyan);
ctx.save();
ctx.translate(20, canvas.height / 2);
ctx.rotate(-Math.PI / 2);
drawText(ctx, 'Income ($k)', 0, 0, 12, COLORS.cyan);
ctx.restore();
// Draw customers
customers.forEach(customer => {
const px = padding + ((customer.age - minAge) / (maxAge - minAge)) * width;
const py = canvas.height - padding - ((customer.income - minIncome) / (maxIncome - minIncome)) * height;
const color = clustered ? (customer.cluster === 0 ? COLORS.cyan : COLORS.orange) : COLORS.primary;
drawCircle(ctx, px, py, 10, color);
drawText(ctx, customer.name, px, py - 15, 12, COLORS.text);
});
// Draw centroids if clustered
if (clustered) {
centroids.forEach((centroid, i) => {
const cx = padding + ((centroid.age - minAge) / (maxAge - minAge)) * width;
const cy = canvas.height - padding - ((centroid.income - minIncome) / (maxIncome - minIncome)) * height;
// Draw X marker for centroid
ctx.strokeStyle = centroid.color;
ctx.lineWidth = 4;
ctx.beginPath();
ctx.moveTo(cx - 12, cy - 12);
ctx.lineTo(cx + 12, cy + 12);
ctx.moveTo(cx + 12, cy - 12);
ctx.lineTo(cx - 12, cy + 12);
ctx.stroke();
drawText(ctx, `C${i + 1} [${centroid.age.toFixed(1)}, ${centroid.income.toFixed(1)}]`,
cx + 20, cy, 11, centroid.color, 'left');
});
drawText(ctx, 'Cluster 1 (Young, Lower Income)', 150, 30, 12, COLORS.cyan);
drawText(ctx, 'Cluster 2 (Mature, Higher Income)', 150, 50, 12, COLORS.orange);
}
}
const clusterBtn = document.getElementById('btn-ml-15-cluster');
const resetBtn = document.getElementById('btn-ml-15-reset');
if (clusterBtn) {
clusterBtn.addEventListener('click', () => {
clustered = true;
assignClusters();
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
clustered = false;
customers.forEach(c => c.cluster = null);
centroids = [
{ age: 25, income: 40, color: COLORS.cyan },
{ age: 60, income: 90, color: COLORS.orange }
];
draw();
});
}
draw();
}
// ===== LINEAR ALGEBRA VISUALIZATIONS =====
function initVectorCanvas() {
const canvas = document.getElementById('canvas-42');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let vx = 3, vy = 2;
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const scale = 40;
// Draw axes
drawLine(ctx, 0, centerY, canvas.width, centerY, '#555', 1);
drawLine(ctx, centerX, 0, centerX, canvas.height, '#555', 1);
// Draw grid
ctx.strokeStyle = '#333';
ctx.lineWidth = 0.5;
for (let i = -10; i <= 10; i++) {
if (i !== 0) {
drawLine(ctx, centerX + i * scale, 0, centerX + i * scale, canvas.height, '#333', 0.5);
drawLine(ctx, 0, centerY + i * scale, canvas.width, centerY + i * scale, '#333', 0.5);
}
}
// Draw vector
const endX = centerX + vx * scale;
const endY = centerY - vy * scale;
// Arrow shaft
drawLine(ctx, centerX, centerY, endX, endY, COLORS.cyan, 3);
// Arrow head
const angle = Math.atan2(vy, vx);
const arrowSize = 15;
ctx.beginPath();
ctx.moveTo(endX, endY);
ctx.lineTo(endX - arrowSize * Math.cos(angle - Math.PI / 6), endY + arrowSize * Math.sin(angle - Math.PI / 6));
ctx.lineTo(endX - arrowSize * Math.cos(angle + Math.PI / 6), endY + arrowSize * Math.sin(angle + Math.PI / 6));
ctx.closePath();
ctx.fillStyle = COLORS.cyan;
ctx.fill();
// Draw vector label
drawText(ctx, `v = [${vx.toFixed(1)}, ${vy.toFixed(1)}]`, endX + 20, endY - 10, 14, COLORS.cyan, 'left');
// Draw magnitude
const magnitude = Math.sqrt(vx * vx + vy * vy);
drawText(ctx, `|v| = ${magnitude.toFixed(2)}`, canvas.width / 2, 30, 14, COLORS.text);
}
const sliderX = document.getElementById('slider42x');
const sliderY = document.getElementById('slider42y');
const labelX = document.getElementById('vec42x');
const labelY = document.getElementById('vec42y');
if (sliderX) {
sliderX.addEventListener('input', (e) => {
vx = parseFloat(e.target.value);
if (labelX) labelX.textContent = vx.toFixed(1);
draw();
});
}
if (sliderY) {
sliderY.addEventListener('input', (e) => {
vy = parseFloat(e.target.value);
if (labelY) labelY.textContent = vy.toFixed(1);
draw();
});
}
const resetBtn = document.getElementById('btn42reset');
if (resetBtn) {
resetBtn.addEventListener('click', () => {
vx = 3; vy = 2;
if (sliderX) sliderX.value = vx;
if (sliderY) sliderY.value = vy;
if (labelX) labelX.textContent = vx;
if (labelY) labelY.textContent = vy;
draw();
});
}
draw();
}
function initSpanCanvas() {
const canvas = document.getElementById('canvas-43');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let animating = false;
let t = 0;
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const scale = 50;
// Draw axes
drawLine(ctx, 0, centerY, canvas.width, centerY, '#555', 1);
drawLine(ctx, centerX, 0, centerX, canvas.height, '#555', 1);
// Basis vectors
const v1 = { x: 2, y: 1 };
const v2 = { x: -1, y: 1.5 };
// Draw basis vectors
drawLine(ctx, centerX, centerY, centerX + v1.x * scale, centerY - v1.y * scale, COLORS.cyan, 3);
drawLine(ctx, centerX, centerY, centerX + v2.x * scale, centerY - v2.y * scale, COLORS.orange, 3);
if (animating) {
// Draw span (multiple linear combinations)
ctx.globalAlpha = 0.3;
for (let a = -2; a <= 2; a += 0.3) {
for (let b = -2; b <= 2; b += 0.3) {
const x = centerX + (a * v1.x + b * v2.x) * scale;
const y = centerY - (a * v1.y + b * v2.y) * scale;
drawCircle(ctx, x, y, 2, COLORS.primary);
}
}
ctx.globalAlpha = 1;
}
drawText(ctx, 'v₁', centerX + v1.x * scale + 20, centerY - v1.y * scale, 16, COLORS.cyan);
drawText(ctx, 'v₂', centerX + v2.x * scale - 20, centerY - v2.y * scale, 16, COLORS.orange);
}
const animateBtn = document.getElementById('btn43animate');
const resetBtn = document.getElementById('btn43reset');
if (animateBtn) {
animateBtn.addEventListener('click', () => {
animating = true;
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
animating = false;
draw();
});
}
draw();
}
function initTransformationGrid() {
const canvas = document.getElementById('canvas-44');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let matrix = [[1, 0], [0, 1]]; // Identity
function drawGrid(transform = false) {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const scale = 40;
const gridSize = 5;
ctx.strokeStyle = transform ? COLORS.cyan : '#555';
ctx.lineWidth = 1;
// Draw grid lines
for (let i = -gridSize; i <= gridSize; i++) {
for (let j = -gridSize; j <= gridSize; j++) {
let x1 = i, y1 = j;
let x2 = i + 1, y2 = j;
let x3 = i, y3 = j + 1;
if (transform) {
[x1, y1] = [matrix[0][0] * i + matrix[0][1] * j, matrix[1][0] * i + matrix[1][1] * j];
[x2, y2] = [matrix[0][0] * (i + 1) + matrix[0][1] * j, matrix[1][0] * (i + 1) + matrix[1][1] * j];
[x3, y3] = [matrix[0][0] * i + matrix[0][1] * (j + 1), matrix[1][0] * i + matrix[1][1] * (j + 1)];
}
drawLine(ctx, centerX + x1 * scale, centerY - y1 * scale, centerX + x2 * scale, centerY - y2 * scale, ctx.strokeStyle, 1);
drawLine(ctx, centerX + x1 * scale, centerY - y1 * scale, centerX + x3 * scale, centerY - y3 * scale, ctx.strokeStyle, 1);
}
}
// Draw i-hat and j-hat
const iHat = transform ? [matrix[0][0], matrix[1][0]] : [1, 0];
const jHat = transform ? [matrix[0][1], matrix[1][1]] : [0, 1];
drawLine(ctx, centerX, centerY, centerX + iHat[0] * scale, centerY - iHat[1] * scale, COLORS.orange, 3);
drawLine(ctx, centerX, centerY, centerX + jHat[0] * scale, centerY - jHat[1] * scale, COLORS.green, 3);
}
const select = document.getElementById('select44');
const applyBtn = document.getElementById('btn44apply');
if (applyBtn && select) {
applyBtn.addEventListener('click', () => {
const type = select.value;
switch (type) {
case 'rotation':
matrix = [[0, -1], [1, 0]];
break;
case 'shear':
matrix = [[1, 1], [0, 1]];
break;
case 'reflection':
matrix = [[1, 0], [0, -1]];
break;
default:
matrix = [[1, 0], [0, 1]];
}
drawGrid(true);
});
}
drawGrid(false);
}
// ===== EIGENVECTOR VISUALIZATION (UPDATED) =====
function initEigenvectorCanvas() {
const canvas = document.getElementById('canvas-54');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let transformed = false;
// Matrix A = [[2, 0], [0, 1]]
const matrix = [[2, 0], [0, 1]];
// Test vectors
const vectors = [
{ x: 1, y: 1, color: '#4a90e2', label: '[1,1] Not Eigenvector', isEigen: false },
{ x: 1, y: 0, color: '#51cf66', label: '[1,0] Eigenvector \u03bb=2', isEigen: true, lambda: 2 },
{ x: 0, y: 1, color: '#ffd93d', label: '[0,1] Eigenvector \u03bb=1', isEigen: true, lambda: 1 }
];
function applyMatrix(v) {
return {
x: matrix[0][0] * v.x + matrix[0][1] * v.y,
y: matrix[1][0] * v.x + matrix[1][1] * v.y
};
}
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const scale = 80;
// Title
drawText(ctx, transformed ? 'After: A \u00d7 v (Matrix Applied)' : 'Before: Original Vectors', centerX, 25, 16, COLORS.cyan);
drawText(ctx, 'Matrix A = [[2, 0], [0, 1]] \u2014 Stretches x-axis by 2', centerX, 45, 12, COLORS.textSecondary);
// Draw grid
ctx.strokeStyle = 'rgba(255,255,255,0.1)';
ctx.lineWidth = 1;
for (let i = -4; i <= 4; i++) {
drawLine(ctx, centerX + i * scale, 60, centerX + i * scale, canvas.height - 40, 'rgba(255,255,255,0.1)', 1);
drawLine(ctx, 40, centerY + i * scale, canvas.width - 40, centerY + i * scale, 'rgba(255,255,255,0.1)', 1);
}
// Draw axes
drawLine(ctx, 40, centerY, canvas.width - 40, centerY, COLORS.text, 2);
drawLine(ctx, centerX, 60, centerX, canvas.height - 40, COLORS.text, 2);
// Draw vectors
vectors.forEach((v, idx) => {
let displayV = transformed ? applyMatrix(v) : v;
const endX = centerX + displayV.x * scale;
const endY = centerY - displayV.y * scale;
// Draw vector arrow
ctx.beginPath();
ctx.strokeStyle = v.color;
ctx.lineWidth = 3;
ctx.moveTo(centerX, centerY);
ctx.lineTo(endX, endY);
ctx.stroke();
// Arrow head
const angle = Math.atan2(centerY - endY, endX - centerX);
ctx.beginPath();
ctx.fillStyle = v.color;
ctx.moveTo(endX, endY);
ctx.lineTo(endX - 15 * Math.cos(angle - 0.3), endY + 15 * Math.sin(angle - 0.3));
ctx.lineTo(endX - 15 * Math.cos(angle + 0.3), endY + 15 * Math.sin(angle + 0.3));
ctx.closePath();
ctx.fill();
// Label
const labelX = endX + 20;
const labelY = endY - 10;
drawText(ctx, `[${displayV.x.toFixed(1)}, ${displayV.y.toFixed(1)}]`, labelX, labelY, 11, v.color, 'left');
});
// Legend
const legendY = canvas.height - 25;
vectors.forEach((v, idx) => {
const x = 80 + idx * 220;
drawCircle(ctx, x, legendY, 6, v.color);
drawText(ctx, v.label, x + 15, legendY + 4, 10, COLORS.text, 'left');
});
}
const transformBtn = document.getElementById('btn54transform');
const resetBtn = document.getElementById('btn54reset');
if (transformBtn) {
transformBtn.addEventListener('click', () => {
transformed = true;
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
transformed = false;
draw();
});
}
draw();
}
// ===== CALCULUS VISUALIZATIONS =====
function initCircleAreaCanvas() {
const canvas = document.getElementById('canvas-58');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let unwrapping = false;
let progress = 0;
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 4;
const centerY = canvas.height / 2;
const radius = 100;
if (!unwrapping) {
// Draw circle
drawCircle(ctx, centerX, centerY, radius, COLORS.cyan, false);
drawText(ctx, 'Circle: Area = πr²', centerX, centerY + radius + 30, 14, COLORS.cyan);
} else {
// Draw unwrapped rings
const rings = 20;
for (let i = 0; i < rings * progress; i++) {
const r = (i / rings) * radius;
const rectX = canvas.width / 2 + i * 3;
const rectY = centerY - r;
const rectHeight = 2 * r;
const dr = radius / rings;
ctx.fillStyle = COLORS.cyan;
ctx.globalAlpha = 0.6;
ctx.fillRect(rectX, rectY, 2, rectHeight);
}
ctx.globalAlpha = 1;
if (progress >= 0.99) {
drawText(ctx, 'Integrated! Area = πr²', canvas.width * 0.7, centerY + 50, 14, COLORS.green);
}
}
}
const animateBtn = document.getElementById('btn58animate');
const resetBtn = document.getElementById('btn58reset');
if (animateBtn) {
animateBtn.addEventListener('click', () => {
unwrapping = true;
progress = 0;
const interval = setInterval(() => {
progress += 0.02;
draw();
if (progress >= 1) {
clearInterval(interval);
}
}, 50);
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
unwrapping = false;
progress = 0;
draw();
});
}
draw();
}
function initDerivativeCanvas() {
const canvas = document.getElementById('canvas-59');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let dx = 1.0;
function f(x) {
return 0.02 * x * x;
}
function draw() {
clearCanvas(ctx, canvas);
const scale = 50;
const centerX = canvas.width / 2;
const centerY = canvas.height * 0.8;
// Draw axes
drawLine(ctx, 50, centerY, canvas.width - 50, centerY, '#555', 1);
drawLine(ctx, centerX, 50, centerX, canvas.height - 50, '#555', 1);
// Draw function
ctx.beginPath();
for (let x = -canvas.width / 2; x < canvas.width / 2; x += 2) {
const px = centerX + x;
const py = centerY - f(x) * scale;
if (x === -canvas.width / 2) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 2;
ctx.stroke();
// Draw secant line
const x0 = 0;
const x1 = dx * scale;
const y0 = centerY - f(x0) * scale;
const y1 = centerY - f(x1) * scale;
drawLine(ctx, centerX + x0 - 50, y0 - (y1 - y0) / x1 * 50, centerX + x1 + 50, y1 + (y1 - y0) / x1 * 50, COLORS.orange, 2);
drawCircle(ctx, centerX + x0, y0, 5, COLORS.green);
drawCircle(ctx, centerX + x1, y1, 5, COLORS.green);
const slope = (f(x1 / scale) - f(0)) / (x1 / scale);
drawText(ctx, `Slope = ${slope.toFixed(3)}`, canvas.width / 2, 40, 14, COLORS.orange);
drawText(ctx, `As Δx → 0, slope → derivative`, canvas.width / 2, 60, 12, COLORS.text);
}
const slider = document.getElementById('slider59dx');
const label = document.getElementById('label59dx');
if (slider) {
slider.addEventListener('input', (e) => {
dx = parseFloat(e.target.value);
if (label) label.textContent = dx.toFixed(1);
draw();
});
}
draw();
}
function initRiemannSumCanvas() {
const canvas = document.getElementById('canvas-64');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let n = 8;
function f(x) {
return 50 + 50 * Math.sin(x / 30);
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 50;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
// Draw axes
drawLine(ctx, padding, height + padding, canvas.width - padding, height + padding, '#555', 2);
drawLine(ctx, padding, padding, padding, height + padding, '#555', 2);
// Draw function
ctx.beginPath();
for (let x = 0; x <= width; x += 2) {
const px = padding + x;
const py = height + padding - f(x);
if (x === 0) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 3;
ctx.stroke();
// Draw rectangles
const rectWidth = width / n;
let totalArea = 0;
for (let i = 0; i < n; i++) {
const x = i * rectWidth;
const rectHeight = f(x);
totalArea += rectWidth * rectHeight;
ctx.fillStyle = COLORS.orange;
ctx.globalAlpha = 0.5;
ctx.fillRect(padding + x, height + padding - rectHeight, rectWidth, rectHeight);
ctx.strokeStyle = COLORS.orange;
ctx.globalAlpha = 1;
ctx.strokeRect(padding + x, height + padding - rectHeight, rectWidth, rectHeight);
}
drawText(ctx, `Rectangles: ${n}`, canvas.width / 2, 30, 14, COLORS.text);
drawText(ctx, `Approximate Area: ${(totalArea / 100).toFixed(2)}`, canvas.width / 2, 50, 12, COLORS.orange);
}
const slider = document.getElementById('slider64n');
const label = document.getElementById('label64n');
if (slider) {
slider.addEventListener('input', (e) => {
n = parseInt(e.target.value);
if (label) label.textContent = n;
draw();
});
}
draw();
}
function initTaylorSeriesCanvas() {
const canvas = document.getElementById('canvas-68');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let degree = 1;
let func = 'sin';
function draw() {
clearCanvas(ctx, canvas);
const scale = 50;
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
// Draw axes
drawLine(ctx, 50, centerY, canvas.width - 50, centerY, '#555', 1);
drawLine(ctx, centerX, 50, centerX, canvas.height - 50, '#555', 1);
// Draw actual function
ctx.beginPath();
for (let x = -canvas.width / 2; x < canvas.width / 2; x += 2) {
const t = x / scale;
let y;
if (func === 'sin') y = Math.sin(t);
else if (func === 'cos') y = Math.cos(t);
else y = Math.exp(t);
const px = centerX + x;
const py = centerY - y * scale;
if (x === -canvas.width / 2) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 2;
ctx.stroke();
// Draw Taylor approximation
ctx.beginPath();
for (let x = -canvas.width / 2; x < canvas.width / 2; x += 2) {
const t = x / scale;
let y = 0;
if (func === 'sin') {
for (let n = 0; n <= degree; n++) {
const term = Math.pow(-1, n) * Math.pow(t, 2 * n + 1) / factorial(2 * n + 1);
y += term;
}
} else if (func === 'cos') {
for (let n = 0; n <= degree; n++) {
const term = Math.pow(-1, n) * Math.pow(t, 2 * n) / factorial(2 * n);
y += term;
}
} else {
for (let n = 0; n <= degree; n++) {
y += Math.pow(t, n) / factorial(n);
}
}
const px = centerX + x;
const py = centerY - y * scale;
if (x === -canvas.width / 2) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.orange;
ctx.lineWidth = 3;
ctx.stroke();
drawText(ctx, `Function: ${func}(x)`, canvas.width / 2, 30, 14, COLORS.cyan);
drawText(ctx, `Taylor degree: ${degree}`, canvas.width / 2, 50, 14, COLORS.orange);
}
function factorial(n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
const slider = document.getElementById('slider68degree');
const label = document.getElementById('label68degree');
const select = document.getElementById('select68func');
if (slider) {
slider.addEventListener('input', (e) => {
degree = parseInt(e.target.value);
if (label) label.textContent = degree;
draw();
});
}
if (select) {
select.addEventListener('change', (e) => {
func = e.target.value;
draw();
});
}
draw();
}
// ===== INTERACTIVE ELEMENTS =====
function initInteractiveElements() {
// Add any additional interactive elements here
// Such as tooltips, modals, etc.
}
// ===== HELPER FUNCTIONS =====
function generateRandomData(count, min, max) {
return Array.from({ length: count }, () =>
Math.floor(Math.random() * (max - min + 1)) + min
);
}
function formatNumber(num, decimals = 2) {
return Number(num).toFixed(decimals);
}
// ===== ANIMATION LOOP =====
function startAnimation(canvasId, animationFunction) {
if (animationFrames[canvasId]) {
cancelAnimationFrame(animationFrames[canvasId]);
}
function animate() {
animationFunction();
animationFrames[canvasId] = requestAnimationFrame(animate);
}
animate();
}
function stopAnimation(canvasId) {
if (animationFrames[canvasId]) {
cancelAnimationFrame(animationFrames[canvasId]);
delete animationFrames[canvasId];
}
}
// ===== CONSOLE LOG =====
// ===== ADDITIONAL ML VISUALIZATIONS =====
function initMLSVMCanvas() {
const canvas = document.getElementById('canvas-ml-9');
if (!canvas) return;
const ctx = canvas.getContext('2d');
// Generate two-class data
const class1 = Array.from({ length: 20 }, () => ({
x: Math.random() * 100 + 50,
y: Math.random() * 100 + 50
}));
const class2 = Array.from({ length: 20 }, () => ({
x: Math.random() * 100 + 200,
y: Math.random() * 100 + 200
}));
function draw() {
clearCanvas(ctx, canvas);
const padding = 50;
// Draw decision boundary (simplified)
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, padding, COLORS.orange, 3);
drawText(ctx, 'Decision Boundary', canvas.width / 2, 30, 14, COLORS.orange);
// Draw margin lines
drawLine(ctx, padding, canvas.height - padding - 30, canvas.width - padding, padding - 30, COLORS.green, 1);
drawLine(ctx, padding, canvas.height - padding + 30, canvas.width - padding, padding + 30, COLORS.green, 1);
drawText(ctx, 'Maximum Margin', canvas.width / 2, 50, 12, COLORS.green);
// Draw data points
class1.forEach(p => drawCircle(ctx, p.x, p.y, 6, COLORS.cyan));
class2.forEach(p => drawCircle(ctx, p.x, p.y, 6, COLORS.primary));
}
draw();
}
function initMLRandomForestCanvas() {
const canvas = document.getElementById('canvas-ml-12');
if (!canvas) return;
const ctx = canvas.getContext('2d');
function draw() {
clearCanvas(ctx, canvas);
drawText(ctx, 'Random Forest: Ensemble of Decision Trees', canvas.width / 2, 50, 16, COLORS.cyan);
// Draw multiple trees
const treeCount = 5;
const treeWidth = (canvas.width - 100) / treeCount;
for (let i = 0; i < treeCount; i++) {
const x = 50 + i * treeWidth + treeWidth / 2;
const y = 100;
// Draw simple tree structure
drawLine(ctx, x, y, x - 30, y + 60, COLORS.green, 2);
drawLine(ctx, x, y, x + 30, y + 60, COLORS.green, 2);
drawCircle(ctx, x, y, 8, COLORS.cyan);
drawCircle(ctx, x - 30, y + 60, 6, COLORS.orange);
drawCircle(ctx, x + 30, y + 60, 6, COLORS.orange);
drawText(ctx, `Tree ${i + 1}`, x, y + 100, 12, COLORS.text);
}
// Draw voting arrow
drawLine(ctx, canvas.width / 2, 200, canvas.width / 2, 280, COLORS.orange, 3);
drawText(ctx, '↓ Majority Vote', canvas.width / 2 + 10, 250, 14, COLORS.orange, 'left');
drawRect(ctx, canvas.width / 2 - 80, 280, 160, 40, COLORS.green);
drawText(ctx, 'Final Prediction', canvas.width / 2, 305, 14, '#000');
}
draw();
}
function initMLGradientBoostingCanvas() {
const canvas = document.getElementById('canvas-ml-13');
if (!canvas) return;
const ctx = canvas.getContext('2d');
function draw() {
clearCanvas(ctx, canvas);
drawText(ctx, 'Gradient Boosting: Sequential Error Correction', canvas.width / 2, 40, 16, COLORS.cyan);
const stages = 4;
const stageWidth = (canvas.width - 100) / stages;
for (let i = 0; i < stages; i++) {
const x = 50 + i * stageWidth;
const y = canvas.height / 2;
// Draw tree
drawRect(ctx, x, y - 40, stageWidth - 40, 80, i === 0 ? COLORS.cyan : COLORS.orange, false);
drawText(ctx, `Tree ${i + 1}`, x + (stageWidth - 40) / 2, y, 12, COLORS.text);
drawText(ctx, i === 0 ? 'Base' : 'Fix Errors', x + (stageWidth - 40) / 2, y + 20, 10, COLORS.textSecondary);
// Draw arrow
if (i < stages - 1) {
drawLine(ctx, x + stageWidth - 40, y, x + stageWidth, y, COLORS.green, 2);
drawText(ctx, '+', x + stageWidth - 20, y - 10, 16, COLORS.green);
}
}
drawText(ctx, 'Each tree learns from previous mistakes', canvas.width / 2, canvas.height - 30, 12, COLORS.text);
}
draw();
}
function initMLNeuralNetworkCanvas() {
const canvas = document.getElementById('canvas-ml-14');
if (!canvas) return;
const ctx = canvas.getContext('2d');
function draw() {
clearCanvas(ctx, canvas);
drawText(ctx, 'Neural Network Architecture', canvas.width / 2, 30, 16, COLORS.cyan);
const layers = [3, 5, 4, 2]; // neurons per layer
const layerSpacing = (canvas.width - 100) / (layers.length - 1);
// Draw connections
ctx.globalAlpha = 0.3;
for (let l = 0; l < layers.length - 1; l++) {
const x1 = 50 + l * layerSpacing;
const x2 = 50 + (l + 1) * layerSpacing;
for (let i = 0; i < layers[l]; i++) {
const y1 = canvas.height / 2 - (layers[l] - 1) * 15 + i * 30;
for (let j = 0; j < layers[l + 1]; j++) {
const y2 = canvas.height / 2 - (layers[l + 1] - 1) * 15 + j * 30;
drawLine(ctx, x1, y1, x2, y2, COLORS.textSecondary, 1);
}
}
}
ctx.globalAlpha = 1;
// Draw neurons
layers.forEach((count, l) => {
const x = 50 + l * layerSpacing;
for (let i = 0; i < count; i++) {
const y = canvas.height / 2 - (count - 1) * 15 + i * 30;
drawCircle(ctx, x, y, 12, l === 0 ? COLORS.cyan : (l === layers.length - 1 ? COLORS.green : COLORS.orange));
}
const layerNames = ['Input', 'Hidden 1', 'Hidden 2', 'Output'];
drawText(ctx, layerNames[l], x, canvas.height - 30, 12, COLORS.text);
});
}
draw();
}
// ===== DATA SCIENCE VISUALIZATIONS =====
function initSimpleRegressionCanvas() {
const canvas = document.getElementById('canvas-70');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let showLine = false;
// Sample data
const data = [
{ x: 1, y: 2.1 }, { x: 2, y: 4.2 }, { x: 3, y: 5.8 }, { x: 4, y: 8.1 },
{ x: 5, y: 10.3 }, { x: 6, y: 12.1 }, { x: 7, y: 13.9 }, { x: 8, y: 16.2 },
{ x: 9, y: 18.1 }, { x: 10, y: 20.0 }
];
function calculateRegression() {
const n = data.length;
const sumX = data.reduce((s, p) => s + p.x, 0);
const sumY = data.reduce((s, p) => s + p.y, 0);
const sumXY = data.reduce((s, p) => s + p.x * p.y, 0);
const sumX2 = data.reduce((s, p) => s + p.x * p.x, 0);
const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
const intercept = (sumY - slope * sumX) / n;
return { slope, intercept };
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const maxX = 11;
const maxY = 22;
// Draw axes
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, canvas.height - padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, canvas.height - padding, COLORS.text, 2);
// Draw grid
for (let i = 0; i <= 10; i++) {
const x = padding + (i / maxX) * width;
const y = canvas.height - padding - (i * 2 / maxY) * height;
drawLine(ctx, x, canvas.height - padding, x, canvas.height - padding + 5, COLORS.textSecondary, 1);
drawText(ctx, i.toString(), x, canvas.height - padding + 20, 10, COLORS.textSecondary);
if (i * 2 <= maxY) {
drawLine(ctx, padding - 5, y, padding, y, COLORS.textSecondary, 1);
drawText(ctx, (i * 2).toString(), padding - 15, y + 4, 10, COLORS.textSecondary, 'right');
}
}
// Draw labels
drawText(ctx, 'X', canvas.width - padding + 20, canvas.height - padding + 4, 12, COLORS.cyan);
drawText(ctx, 'Y', padding - 4, padding - 20, 12, COLORS.cyan);
// Draw data points
data.forEach(point => {
const x = padding + (point.x / maxX) * width;
const y = canvas.height - padding - (point.y / maxY) * height;
drawCircle(ctx, x, y, 6, COLORS.cyan);
});
// Draw regression line
if (showLine) {
const { slope, intercept } = calculateRegression();
const x1 = 0;
const y1 = intercept;
const x2 = maxX;
const y2 = slope * x2 + intercept;
const px1 = padding + (x1 / maxX) * width;
const py1 = canvas.height - padding - (y1 / maxY) * height;
const px2 = padding + (x2 / maxX) * width;
const py2 = canvas.height - padding - (y2 / maxY) * height;
drawLine(ctx, px1, py1, px2, py2, COLORS.orange, 3);
// Calculate R²
const meanY = data.reduce((s, p) => s + p.y, 0) / data.length;
let ssTot = 0, ssRes = 0;
data.forEach(point => {
const predicted = slope * point.x + intercept;
ssRes += Math.pow(point.y - predicted, 2);
ssTot += Math.pow(point.y - meanY, 2);
});
const r2 = 1 - (ssRes / ssTot);
drawText(ctx, `y = ${intercept.toFixed(2)} + ${slope.toFixed(2)}x`, canvas.width / 2, 30, 14, COLORS.orange);
drawText(ctx, `R² = ${r2.toFixed(4)}`, canvas.width / 2, 50, 14, COLORS.green);
} else {
drawText(ctx, 'Click "Fit Regression Line" to see the best fit', canvas.width / 2, 30, 14, COLORS.text);
}
}
const fitBtn = document.getElementById('btn70fit');
const resetBtn = document.getElementById('btn70reset');
if (fitBtn) {
fitBtn.addEventListener('click', () => {
showLine = true;
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
showLine = false;
draw();
});
}
draw();
}
function initLogisticRegressionCanvas() {
const canvas = document.getElementById('canvas-72');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let threshold = 0.5;
function sigmoid(z) {
return 1 / (1 + Math.exp(-z));
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
// Draw axes
const centerY = canvas.height / 2;
drawLine(ctx, padding, centerY, canvas.width - padding, centerY, COLORS.text, 2);
drawLine(ctx, canvas.width / 2, padding, canvas.width / 2, canvas.height - padding, COLORS.text, 2);
// Draw sigmoid curve
ctx.beginPath();
for (let x = -6; x <= 6; x += 0.1) {
const px = canvas.width / 2 + (x / 6) * (width / 2);
const y = sigmoid(x);
const py = canvas.height - padding - y * height;
if (x === -6) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 3;
ctx.stroke();
// Draw threshold line
const thresholdY = canvas.height - padding - threshold * height;
drawLine(ctx, padding, thresholdY, canvas.width - padding, thresholdY, COLORS.orange, 2);
drawText(ctx, `Threshold = ${threshold.toFixed(2)}`, canvas.width - 100, thresholdY - 10, 12, COLORS.orange);
// Draw labels
drawText(ctx, 'P(y=1) = σ(z) = 1/(1+e^(-z))', canvas.width / 2, 30, 14, COLORS.cyan);
drawText(ctx, 'Class 1 (if P ≥ threshold)', canvas.width - 150, thresholdY - 30, 12, COLORS.green);
drawText(ctx, 'Class 0 (if P < threshold)', canvas.width - 150, thresholdY + 30, 12, COLORS.textSecondary);
// Draw axis labels
drawText(ctx, '0', canvas.width / 2 + 5, centerY + 20, 10, COLORS.text, 'left');
drawText(ctx, '1', padding - 20, padding + 10, 10, COLORS.text);
}
const slider = document.getElementById('slider72');
const label = document.getElementById('label72');
if (slider) {
slider.addEventListener('input', (e) => {
threshold = parseFloat(e.target.value);
if (label) label.textContent = threshold.toFixed(2);
draw();
});
}
draw();
}
function initPolynomialRegressionCanvas() {
const canvas = document.getElementById('canvas-74');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let degree = 1;
// Generate sample data with some noise
const trueFunc = (x) => 0.5 * x * x - 3 * x + 5;
const data = [];
for (let x = 0; x <= 10; x += 0.5) {
data.push({ x, y: trueFunc(x) + (Math.random() - 0.5) * 2 });
}
function fitPolynomial(degree) {
// Simple polynomial fit (not production-quality)
return (x) => {
if (degree === 1) return 0.5 * x + 1;
if (degree === 2) return 0.5 * x * x - 3 * x + 5;
if (degree === 3) return 0.05 * x * x * x - 0.2 * x * x - 2 * x + 5;
return trueFunc(x);
};
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const maxX = 10;
const maxY = 15;
// Draw axes
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, canvas.height - padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, canvas.height - padding, COLORS.text, 2);
// Draw data points
data.forEach(point => {
const px = padding + (point.x / maxX) * width;
const py = canvas.height - padding - (point.y / maxY) * height;
drawCircle(ctx, px, py, 4, COLORS.cyan);
});
// Draw polynomial fit
const polyFunc = fitPolynomial(degree);
ctx.beginPath();
for (let x = 0; x <= maxX; x += 0.1) {
const px = padding + (x / maxX) * width;
const y = polyFunc(x);
const py = canvas.height - padding - (y / maxY) * height;
if (x === 0) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.orange;
ctx.lineWidth = 3;
ctx.stroke();
drawText(ctx, `Polynomial Degree: ${degree}`, canvas.width / 2, 30, 14, COLORS.orange);
if (degree > 5) {
drawText(ctx, 'High degree may overfit!', canvas.width / 2, 50, 12, COLORS.orange);
}
}
const slider = document.getElementById('slider74');
const label = document.getElementById('label74');
if (slider) {
slider.addEventListener('input', (e) => {
degree = parseInt(e.target.value);
if (label) label.textContent = degree;
draw();
});
}
draw();
}
function initPCACanvas() {
const canvas = document.getElementById('canvas-77');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let showPCs = false;
// Generate 2D data
const data = [];
for (let i = 0; i < 50; i++) {
const x = Math.random() * 4 - 2;
const y = 0.8 * x + Math.random() * 0.5;
data.push({ x, y });
}
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const scale = 80;
// Draw axes
drawLine(ctx, 0, centerY, canvas.width, centerY, '#555', 1);
drawLine(ctx, centerX, 0, centerX, canvas.height, '#555', 1);
// Draw data points
data.forEach(point => {
const px = centerX + point.x * scale;
const py = centerY - point.y * scale;
drawCircle(ctx, px, py, 5, COLORS.cyan);
});
if (showPCs) {
// Draw PC1 (main direction)
const pc1Angle = Math.atan(0.8);
const pc1Length = 150;
drawLine(ctx,
centerX - pc1Length * Math.cos(pc1Angle),
centerY + pc1Length * Math.sin(pc1Angle),
centerX + pc1Length * Math.cos(pc1Angle),
centerY - pc1Length * Math.sin(pc1Angle),
COLORS.orange, 3
);
drawText(ctx, 'PC1 (80% variance)', centerX + 100, centerY - 80, 14, COLORS.orange);
// Draw PC2 (perpendicular)
const pc2Angle = pc1Angle + Math.PI / 2;
const pc2Length = 80;
drawLine(ctx,
centerX - pc2Length * Math.cos(pc2Angle),
centerY + pc2Length * Math.sin(pc2Angle),
centerX + pc2Length * Math.cos(pc2Angle),
centerY - pc2Length * Math.sin(pc2Angle),
COLORS.green, 3
);
drawText(ctx, 'PC2 (20% variance)', centerX - 100, centerY - 80, 14, COLORS.green);
}
drawText(ctx, 'PCA finds directions of maximum variance', canvas.width / 2, 30, 14, COLORS.cyan);
}
const projectBtn = document.getElementById('btn77project');
const resetBtn = document.getElementById('btn77reset');
if (projectBtn) {
projectBtn.addEventListener('click', () => {
showPCs = true;
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
showPCs = false;
draw();
});
}
draw();
}
function initGradientDescentCanvas() {
const canvas = document.getElementById('canvas-80');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let learningRate = 0.1;
let animating = false;
let path = [];
// Simple quadratic function
const f = (x) => (x - 3) * (x - 3) + 2;
const df = (x) => 2 * (x - 3);
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const xMin = 0, xMax = 6;
const yMax = 12;
// Draw axes
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, canvas.height - padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, canvas.height - padding, COLORS.text, 2);
// Draw function
ctx.beginPath();
for (let x = xMin; x <= xMax; x += 0.05) {
const px = padding + ((x - xMin) / (xMax - xMin)) * width;
const y = f(x);
const py = canvas.height - padding - (y / yMax) * height;
if (x === xMin) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 2;
ctx.stroke();
// Draw path
if (path.length > 0) {
ctx.beginPath();
path.forEach((point, i) => {
const px = padding + ((point.x - xMin) / (xMax - xMin)) * width;
const py = canvas.height - padding - (point.y / yMax) * height;
if (i === 0) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
drawCircle(ctx, px, py, 5, COLORS.orange);
});
ctx.strokeStyle = COLORS.orange;
ctx.lineWidth = 2;
ctx.stroke();
}
drawText(ctx, 'Gradient Descent: Following negative gradient to minimum', canvas.width / 2, 30, 14, COLORS.cyan);
drawText(ctx, `Learning Rate: ${learningRate.toFixed(2)}`, canvas.width / 2, 50, 12, COLORS.text);
}
function startDescent() {
if (animating) return;
animating = true;
path = [{ x: 0.5, y: f(0.5) }];
const interval = setInterval(() => {
const current = path[path.length - 1];
const grad = df(current.x);
const nextX = current.x - learningRate * grad;
if (Math.abs(grad) < 0.01 || path.length > 50) {
clearInterval(interval);
animating = false;
return;
}
path.push({ x: nextX, y: f(nextX) });
draw();
}, 200);
}
const slider = document.getElementById('slider80');
const label = document.getElementById('label80');
const startBtn = document.getElementById('btn80start');
const resetBtn = document.getElementById('btn80reset');
if (slider) {
slider.addEventListener('input', (e) => {
learningRate = parseFloat(e.target.value);
if (label) label.textContent = learningRate.toFixed(2);
});
}
if (startBtn) {
startBtn.addEventListener('click', startDescent);
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
path = [];
animating = false;
draw();
});
}
draw();
}
function initLossLandscapeCanvas() {
const canvas = document.getElementById('canvas-85');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let lossType = 'mse';
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
// True value
const trueVal = 5;
// Draw axes
drawLine(ctx, padding, canvas.height - padding, canvas.width - padding, canvas.height - padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, canvas.height - padding, COLORS.text, 2);
// Draw loss function
ctx.beginPath();
for (let pred = 0; pred <= 10; pred += 0.1) {
let loss;
if (lossType === 'mse') {
loss = Math.pow(trueVal - pred, 2);
} else if (lossType === 'mae') {
loss = Math.abs(trueVal - pred);
} else {
// Simplified cross-entropy
loss = -Math.log(Math.max(0.01, 1 - Math.abs(trueVal - pred) / 10));
}
const px = padding + (pred / 10) * width;
const py = canvas.height - padding - (loss / 30) * height;
if (pred === 0) {
ctx.moveTo(px, py);
} else {
ctx.lineTo(px, py);
}
}
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 3;
ctx.stroke();
// Draw minimum
const minX = padding + (trueVal / 10) * width;
drawLine(ctx, minX, canvas.height - padding, minX, padding, COLORS.orange, 2);
drawText(ctx, 'Minimum', minX + 10, padding + 20, 12, COLORS.orange);
const lossNames = {
'mse': 'Mean Squared Error: (y - ŷ)²',
'mae': 'Mean Absolute Error: |y - ŷ|',
'cross': 'Cross-Entropy Loss'
};
drawText(ctx, lossNames[lossType], canvas.width / 2, 30, 14, COLORS.cyan);
drawText(ctx, 'Predicted Value →', canvas.width - 100, canvas.height - 30, 12, COLORS.text);
drawText(ctx, 'Loss ↑', padding - 40, padding, 12, COLORS.text);
}
const select = document.getElementById('select85');
if (select) {
select.addEventListener('change', (e) => {
lossType = e.target.value;
draw();
});
}
draw();
}
// ========== SEARCH FUNCTIONALITY ==========
function initSearch() {
const searchInput = document.getElementById('globalSearch');
const searchResults = document.getElementById('searchResults');
if (!searchInput || !searchResults) return;
// Build search index from all topics
const searchIndex = [];
document.querySelectorAll('.topic-section').forEach(section => {
const id = section.id;
const header = section.querySelector('h2');
const subtitle = section.querySelector('.topic-subtitle');
const content = section.textContent.substring(0, 500);
const subject = section.dataset.subject || 'statistics';
if (header) {
searchIndex.push({
id: id,
title: header.textContent,
subtitle: subtitle ? subtitle.textContent : '',
content: content,
subject: subject
});
}
});
searchInput.addEventListener('input', (e) => {
const query = e.target.value.toLowerCase().trim();
if (query.length < 2) {
searchResults.classList.remove('active');
return;
}
const results = searchIndex.filter(item =>
item.title.toLowerCase().includes(query) ||
item.subtitle.toLowerCase().includes(query) ||
item.content.toLowerCase().includes(query)
).slice(0, 8);
if (results.length === 0) {
searchResults.innerHTML = '<div class="no-results">No topics found for "' + query + '"</div>';
} else {
searchResults.innerHTML = results.map(result => `
<div class="search-result-item" data-topic-id="${result.id}" data-subject="${result.subject}">
<div class="search-result-title">${highlightMatch(result.title, query)}</div>
<div class="search-result-subject">${result.subject.replace('-', ' ')}</div>
</div>
`).join('');
}
searchResults.classList.add('active');
});
// Handle result clicks
searchResults.addEventListener('click', (e) => {
const item = e.target.closest('.search-result-item');
if (item) {
const topicId = item.dataset.topicId;
const subject = item.dataset.subject;
// Switch to correct subject first
switchSubject(subject);
// Then scroll to topic
setTimeout(() => {
const target = document.getElementById(topicId);
if (target) {
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}, 200);
searchResults.classList.remove('active');
searchInput.value = '';
}
});
// Close on outside click
document.addEventListener('click', (e) => {
if (!searchInput.contains(e.target) && !searchResults.contains(e.target)) {
searchResults.classList.remove('active');
}
});
// Close on Escape
searchInput.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
searchResults.classList.remove('active');
searchInput.blur();
}
});
}
function highlightMatch(text, query) {
const regex = new RegExp(`(${query})`, 'gi');
return text.replace(regex, '<span class="search-highlight">$1</span>');
}
// ========== PROGRESS TRACKING ==========
const STORAGE_KEY = 'math_mastery_progress';
function initProgressTracking() {
loadProgress();
addCompletionButtons();
updateProgressDisplay();
}
function loadProgress() {
try {
const saved = localStorage.getItem(STORAGE_KEY);
if (saved) {
const completed = JSON.parse(saved);
completed.forEach(topicId => {
markTopicComplete(topicId, false);
});
}
} catch (e) {
console.warn('Could not load progress:', e);
}
}
function saveProgress() {
try {
const completed = [];
document.querySelectorAll('.topic-complete-btn.completed').forEach(btn => {
completed.push(btn.dataset.topicId);
});
localStorage.setItem(STORAGE_KEY, JSON.stringify(completed));
} catch (e) {
console.warn('Could not save progress:', e);
}
}
function addCompletionButtons() {
document.querySelectorAll('.topic-section').forEach(section => {
const topicId = section.id;
const summaryCard = section.querySelector('.summary-card');
if (summaryCard && !section.querySelector('.topic-complete-btn')) {
const btn = document.createElement('button');
btn.className = 'topic-complete-btn';
btn.dataset.topicId = topicId;
btn.innerHTML = '<span class="check-icon"></span> Mark as Complete';
btn.addEventListener('click', () => {
toggleTopicComplete(topicId);
});
summaryCard.appendChild(btn);
}
});
}
function toggleTopicComplete(topicId) {
const btn = document.querySelector(`.topic-complete-btn[data-topic-id="${topicId}"]`);
if (btn) {
const isCompleted = btn.classList.toggle('completed');
btn.innerHTML = isCompleted
? '<span class="check-icon"></span> Completed!'
: '<span class="check-icon"></span> Mark as Complete';
// Update sidebar link
const sidebarLink = document.querySelector(`[data-topic="${topicId}"], [data-topic="${topicId.replace('topic-', '')}"]`);
if (sidebarLink) {
sidebarLink.classList.toggle('completed', isCompleted);
}
saveProgress();
updateProgressDisplay();
}
}
function markTopicComplete(topicId, save = true) {
const btn = document.querySelector(`.topic-complete-btn[data-topic-id="${topicId}"]`);
if (btn && !btn.classList.contains('completed')) {
btn.classList.add('completed');
btn.innerHTML = '<span class="check-icon"></span> Completed!';
const sidebarLink = document.querySelector(`[data-topic="${topicId}"], [data-topic="${topicId.replace('topic-', '')}"]`);
if (sidebarLink) {
sidebarLink.classList.add('completed');
}
if (save) {
saveProgress();
updateProgressDisplay();
}
}
}
function updateProgressDisplay() {
// Progress bar removed - keeping function for compatibility
// Can be used for console logging if needed
}
// ========== ROBUST CANVAS INITIALIZATION ==========
function ensureCanvasVisible(canvasId, callback) {
const canvas = document.getElementById(canvasId);
if (!canvas) return;
// Already initialized
if (canvas.dataset.initialized === 'true') return;
// Check visibility
if (canvas.offsetWidth === 0) {
setTimeout(() => ensureCanvasVisible(canvasId, callback), 100);
return;
}
// Mark and execute
canvas.dataset.initialized = 'true';
callback();
}
// ========== LAZY LOADING FOR VISUALIZATIONS ==========
function initLazyLoading() {
const observerOptions = {
root: null,
rootMargin: '100px',
threshold: 0.1
};
const lazyObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const section = entry.target;
const canvases = section.querySelectorAll('canvas:not([data-initialized="true"])');
canvases.forEach(canvas => {
const initFn = canvas.dataset.initFn;
if (initFn && window[initFn]) {
ensureCanvasVisible(canvas.id, window[initFn]);
}
});
lazyObserver.unobserve(section);
}
});
}, observerOptions);
document.querySelectorAll('.topic-section').forEach(section => {
lazyObserver.observe(section);
});
}
// ========== INTERACTIVE ELEMENTS ==========
function initInteractiveElements() {
// Toggle visibility for practice answers
document.querySelectorAll('.show-answers-btn').forEach(btn => {
btn.addEventListener('click', () => {
const answers = btn.nextElementSibling;
if (answers && answers.classList.contains('practice-answers')) {
const isHidden = answers.style.display === 'none' || !answers.style.display;
answers.style.display = isHidden ? 'block' : 'none';
btn.textContent = isHidden ? 'Hide Answers' : 'Show Answers';
}
});
});
// Initialize formula tooltips
document.querySelectorAll('.formula-var').forEach(el => {
el.style.cursor = 'help';
});
}
// ========== KEYBOARD SHORTCUTS ==========
function initKeyboardShortcuts() {
document.addEventListener('keydown', (e) => {
// Ctrl/Cmd + K for search
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
const searchInput = document.getElementById('globalSearch');
if (searchInput) {
searchInput.focus();
}
}
// Arrow keys for topic navigation
if (e.altKey && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
e.preventDefault();
navigateTopics(e.key === 'ArrowDown' ? 1 : -1);
}
});
}
function navigateTopics(direction) {
const visibleTopics = Array.from(document.querySelectorAll('.topic-section'))
.filter(t => t.style.display !== 'none');
const currentActive = document.querySelector('.topic-link.active');
let currentIndex = 0;
if (currentActive) {
const currentId = currentActive.getAttribute('data-topic');
currentIndex = visibleTopics.findIndex(t =>
t.id === currentId || t.id === `topic-${currentId}`
);
}
const newIndex = Math.max(0, Math.min(visibleTopics.length - 1, currentIndex + direction));
if (visibleTopics[newIndex]) {
visibleTopics[newIndex].scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
console.log('%c📊 Ultimate Learning Platform Loaded', 'color: #64ffda; font-size: 16px; font-weight: bold;');
console.log('%cReady to explore 125+ comprehensive topics across 5 subjects!', 'color: #4a90e2; font-size: 14px;');
console.log('%c✓ Statistics (41) ✓ Linear Algebra (16) ✓ Calculus (12) ✓ Data Science (16) ✓ Machine Learning (40+)', 'color: #51cf66; font-size: 12px;');
// ===== TOGGLE ANSWER FUNCTION =====
/**
* toggleAnswer - Robust Show/Hide Answer Function for practice problems
* @param {string} answerId - The ID of the answer element to toggle
*/
function toggleAnswer(answerId) {
const answerElement = document.getElementById(answerId);
if (!answerElement) {
console.warn(`Element with ID "${answerId}" not found.`);
return;
}
// Find the button that triggered this
const allButtons = document.querySelectorAll('.show-answer-btn');
let triggerButton = null;
allButtons.forEach(btn => {
const onclickAttr = btn.getAttribute('onclick');
if (onclickAttr && onclickAttr.includes(answerId)) {
triggerButton = btn;
}
});
// Toggle display
const isHidden = answerElement.style.display === 'none' ||
getComputedStyle(answerElement).display === 'none' ||
answerElement.style.display === '';
if (isHidden) {
answerElement.style.display = 'block';
if (triggerButton) {
triggerButton.textContent = 'Hide Answers';
triggerButton.classList.add('active');
}
} else {
answerElement.style.display = 'none';
if (triggerButton) {
triggerButton.textContent = 'Show Answers';
triggerButton.classList.remove('active');
}
}
}
// ===== FIX ALL SHOW ANSWER BUTTONS (EVENT DELEGATION) =====
document.addEventListener('DOMContentLoaded', function () {
// Use event delegation to handle all show answer buttons
document.addEventListener('click', function (e) {
// Check if clicked element is a show-answers button
if (e.target.classList.contains('show-answers-btn') ||
e.target.classList.contains('show-answer-btn')) {
e.preventDefault();
e.stopPropagation();
const btn = e.target;
const answerDiv = btn.nextElementSibling;
if (answerDiv && (answerDiv.classList.contains('practice-answers') ||
answerDiv.classList.contains('answer-content') ||
answerDiv.id && answerDiv.id.includes('answer'))) {
// Toggle display
if (answerDiv.style.display === 'none' || answerDiv.style.display === '') {
answerDiv.style.display = 'block';
btn.textContent = 'Hide Answers';
btn.classList.add('active');
} else {
answerDiv.style.display = 'none';
btn.textContent = 'Show Answers';
btn.classList.remove('active');
}
}
}
});
// Ensure all answer divs start hidden
document.querySelectorAll('.practice-answers, .answer-content').forEach(el => {
el.style.display = 'none';
});
// Fix button text (remove line breaks)
document.querySelectorAll('.show-answers-btn, .show-answer-btn').forEach(btn => {
const text = btn.textContent.trim();
if (text.includes('Show') && text.includes('Answers')) {
btn.textContent = 'Show Answers';
}
});
console.log('%c✓ Show Answer Buttons Fixed', 'color: #51cf66;');
});
// ===== TOPIC 10: SKEWNESS VISUALIZATION =====
function initSkewnessVisualization() {
const canvas = document.getElementById('skewnessCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let animating = false;
function normalPDF(x, mean, std) {
return Math.exp(-0.5 * Math.pow((x - mean) / std, 2)) / (std * Math.sqrt(2 * Math.PI));
}
function betaPDF(x, alpha, beta) {
if (x <= 0 || x >= 1) return 0;
const B = (Math.pow(x, alpha - 1) * Math.pow(1 - x, beta - 1));
return B * 3; // Scale for visibility
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 50;
const chartWidth = (canvas.width - padding * 4) / 3;
const chartHeight = canvas.height - padding * 3;
// Title
drawText(ctx, 'Types of Skewness: Where Mean, Median, and Mode Fall', canvas.width / 2, 25, 16, COLORS.cyan);
const charts = [
{ title: 'NEGATIVE (Left) Skew', color: '#64ffda', type: 'left', meanPos: 0.35, medianPos: 0.5, modePos: 0.65 },
{ title: 'SYMMETRIC (No Skew)', color: '#4a90e2', type: 'symmetric', meanPos: 0.5, medianPos: 0.5, modePos: 0.5 },
{ title: 'POSITIVE (Right) Skew', color: '#ff6b6b', type: 'right', meanPos: 0.65, medianPos: 0.5, modePos: 0.35 }
];
charts.forEach((chart, i) => {
const startX = padding + i * (chartWidth + padding);
const startY = padding + 30;
// Draw axes
drawLine(ctx, startX, startY + chartHeight, startX + chartWidth, startY + chartHeight, COLORS.text, 2);
// Draw distribution curve
ctx.beginPath();
ctx.strokeStyle = chart.color;
ctx.lineWidth = 3;
for (let px = 0; px <= chartWidth; px++) {
const x = px / chartWidth;
let y;
if (chart.type === 'left') {
y = betaPDF(x, 5, 2);
} else if (chart.type === 'right') {
y = betaPDF(x, 2, 5);
} else {
y = normalPDF(x, 0.5, 0.15) * 0.15;
}
const plotX = startX + px;
const plotY = startY + chartHeight - y * chartHeight * 0.8;
if (px === 0) ctx.moveTo(plotX, plotY);
else ctx.lineTo(plotX, plotY);
}
ctx.stroke();
// Fill under curve
ctx.globalAlpha = 0.2;
ctx.fillStyle = chart.color;
ctx.lineTo(startX + chartWidth, startY + chartHeight);
ctx.lineTo(startX, startY + chartHeight);
ctx.closePath();
ctx.fill();
ctx.globalAlpha = 1;
// Draw Mean, Median, Mode lines
const measures = [
{ pos: chart.modePos, label: 'Mode', color: '#ff6b6b', dash: [5, 5] },
{ pos: chart.medianPos, label: 'Median', color: '#ffd93d', dash: [10, 5] },
{ pos: chart.meanPos, label: 'Mean', color: '#51cf66', dash: [2, 2] }
];
measures.forEach((m, idx) => {
const lineX = startX + m.pos * chartWidth;
ctx.setLineDash(m.dash);
drawLine(ctx, lineX, startY + 20, lineX, startY + chartHeight, m.color, 2);
ctx.setLineDash([]);
drawText(ctx, m.label, lineX, startY + 10 + idx * 12, 10, m.color);
});
// Title
drawText(ctx, chart.title, startX + chartWidth / 2, startY + chartHeight + 25, 12, chart.color);
// Relationship text
let relText = '';
if (chart.type === 'left') relText = 'Mean < Median < Mode';
else if (chart.type === 'right') relText = 'Mode < Median < Mean';
else relText = 'Mean = Median = Mode';
drawText(ctx, relText, startX + chartWidth / 2, startY + chartHeight + 45, 10, COLORS.text);
});
}
const animateBtn = document.getElementById('skewnessAnimateBtn');
const resetBtn = document.getElementById('skewnessResetBtn');
if (animateBtn) animateBtn.addEventListener('click', draw);
if (resetBtn) resetBtn.addEventListener('click', draw);
draw();
}
// ===== TOPIC 20: PDF vs CDF VISUALIZATION =====
function initPDFCDFVisualization() {
const canvas = document.getElementById('pdfCdfCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let rangeStart = 3, rangeEnd = 7;
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const chartWidth = (canvas.width - padding * 3) / 2;
const chartHeight = canvas.height - padding * 2.5;
// Title
drawText(ctx, 'PDF vs CDF: Uniform Distribution [0, 10]', canvas.width / 2, 25, 16, COLORS.cyan);
// PDF (Left side)
const pdfStartX = padding;
const pdfStartY = padding + 20;
drawText(ctx, 'PDF: Probability Density Function', pdfStartX + chartWidth / 2, pdfStartY - 5, 14, '#64ffda');
// Axes
drawLine(ctx, pdfStartX, pdfStartY + chartHeight, pdfStartX + chartWidth, pdfStartY + chartHeight, COLORS.text, 2);
drawLine(ctx, pdfStartX, pdfStartY, pdfStartX, pdfStartY + chartHeight, COLORS.text, 2);
// X-axis labels
for (let i = 0; i <= 10; i += 2) {
const x = pdfStartX + (i / 10) * chartWidth;
drawText(ctx, i.toString(), x, pdfStartY + chartHeight + 15, 10, COLORS.textSecondary);
}
// PDF rectangle (height = 0.1 for uniform [0,10])
const pdfHeight = chartHeight * 0.4;
ctx.fillStyle = 'rgba(100, 255, 218, 0.2)';
ctx.fillRect(pdfStartX, pdfStartY + chartHeight - pdfHeight, chartWidth, pdfHeight);
ctx.strokeStyle = '#64ffda';
ctx.lineWidth = 2;
ctx.strokeRect(pdfStartX, pdfStartY + chartHeight - pdfHeight, chartWidth, pdfHeight);
// Shade the selected range
const rangeX1 = pdfStartX + (rangeStart / 10) * chartWidth;
const rangeX2 = pdfStartX + (rangeEnd / 10) * chartWidth;
ctx.fillStyle = 'rgba(255, 107, 107, 0.5)';
ctx.fillRect(rangeX1, pdfStartY + chartHeight - pdfHeight, rangeX2 - rangeX1, pdfHeight);
// Labels
drawText(ctx, 'Height = 0.1', pdfStartX + chartWidth + 10, pdfStartY + chartHeight - pdfHeight / 2, 10, COLORS.cyan, 'left');
const prob = ((rangeEnd - rangeStart) / 10).toFixed(2);
drawText(ctx, `P(${rangeStart} ≤ X ≤ ${rangeEnd}) = ${prob}`, pdfStartX + chartWidth / 2, pdfStartY + chartHeight - pdfHeight - 15, 12, '#ff6b6b');
drawText(ctx, `Area = (${rangeEnd}-${rangeStart}) × 0.1 = ${prob}`, pdfStartX + chartWidth / 2, pdfStartY + chartHeight - pdfHeight / 2, 11, '#ff6b6b');
// CDF (Right side)
const cdfStartX = padding * 2 + chartWidth;
const cdfStartY = pdfStartY;
drawText(ctx, 'CDF: Cumulative Distribution Function', cdfStartX + chartWidth / 2, cdfStartY - 5, 14, '#ff6b6b');
// Axes
drawLine(ctx, cdfStartX, cdfStartY + chartHeight, cdfStartX + chartWidth, cdfStartY + chartHeight, COLORS.text, 2);
drawLine(ctx, cdfStartX, cdfStartY, cdfStartX, cdfStartY + chartHeight, COLORS.text, 2);
// X-axis labels
for (let i = 0; i <= 10; i += 2) {
const x = cdfStartX + (i / 10) * chartWidth;
drawText(ctx, i.toString(), x, cdfStartY + chartHeight + 15, 10, COLORS.textSecondary);
}
// Y-axis labels
for (let i = 0; i <= 1; i += 0.2) {
const y = cdfStartY + chartHeight - i * chartHeight;
drawText(ctx, i.toFixed(1), cdfStartX - 20, y + 4, 10, COLORS.textSecondary);
}
// CDF ramp line
ctx.beginPath();
ctx.strokeStyle = '#ff6b6b';
ctx.lineWidth = 3;
ctx.moveTo(cdfStartX, cdfStartY + chartHeight);
ctx.lineTo(cdfStartX + chartWidth, cdfStartY);
ctx.stroke();
// Mark points for selected range
const cdfY1 = cdfStartY + chartHeight - (rangeStart / 10) * chartHeight;
const cdfY2 = cdfStartY + chartHeight - (rangeEnd / 10) * chartHeight;
const cdfX1 = cdfStartX + (rangeStart / 10) * chartWidth;
const cdfX2 = cdfStartX + (rangeEnd / 10) * chartWidth;
drawCircle(ctx, cdfX1, cdfY1, 6, '#ffd93d');
drawCircle(ctx, cdfX2, cdfY2, 6, '#ffd93d');
// Dashed lines to points
ctx.setLineDash([5, 5]);
drawLine(ctx, cdfX1, cdfY1, cdfX1, cdfStartY + chartHeight, '#ffd93d', 1);
drawLine(ctx, cdfX2, cdfY2, cdfX2, cdfStartY + chartHeight, '#ffd93d', 1);
drawLine(ctx, cdfStartX, cdfY1, cdfX1, cdfY1, '#ffd93d', 1);
drawLine(ctx, cdfStartX, cdfY2, cdfX2, cdfY2, '#ffd93d', 1);
ctx.setLineDash([]);
drawText(ctx, `F(${rangeStart}) = ${(rangeStart / 10).toFixed(1)}`, cdfX1 + 10, cdfY1 - 10, 10, '#ffd93d', 'left');
drawText(ctx, `F(${rangeEnd}) = ${(rangeEnd / 10).toFixed(1)}`, cdfX2 + 10, cdfY2 - 10, 10, '#ffd93d', 'left');
// Relationship
drawText(ctx, `P(${rangeStart}≤X≤${rangeEnd}) = F(${rangeEnd}) - F(${rangeStart}) = ${prob}`,
cdfStartX + chartWidth / 2, cdfStartY + chartHeight / 2, 11, '#64ffda');
// Key insight
drawText(ctx, '💡 Area under PDF = Height on CDF', canvas.width / 2, canvas.height - 20, 14, COLORS.cyan);
}
const slider1 = document.getElementById('pdfRangeSlider');
const slider2 = document.getElementById('pdfRangeSlider2');
const label = document.getElementById('pdfRangeLabel');
const animateBtn = document.getElementById('pdfCdfAnimateBtn');
function updateSliders() {
rangeStart = parseFloat(slider1.value);
rangeEnd = parseFloat(slider2.value);
if (rangeEnd < rangeStart) {
const temp = rangeStart;
rangeStart = rangeEnd;
rangeEnd = temp;
}
if (label) label.textContent = `[${rangeStart}, ${rangeEnd}]`;
draw();
}
if (slider1) slider1.addEventListener('input', updateSliders);
if (slider2) slider2.addEventListener('input', updateSliders);
if (animateBtn) animateBtn.addEventListener('click', draw);
draw();
}
// ===== TOPIC 24: NORMAL DISTRIBUTION 68-95-99.7 RULE =====
function initNormalRuleVisualization() {
const canvas = document.getElementById('normalRuleCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let showLevel = 'all'; // '1', '2', '3', or 'all'
function normalPDF(x) {
return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI);
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const width = canvas.width - padding * 2;
const height = canvas.height - padding * 2;
const centerX = canvas.width / 2;
const centerY = padding + height * 0.85;
const scale = width / 8; // -4 to +4 std devs
// Title
drawText(ctx, 'The 68-95-99.7 Rule (Empirical Rule)', canvas.width / 2, 25, 18, COLORS.cyan);
// Draw axes
drawLine(ctx, padding, centerY, canvas.width - padding, centerY, COLORS.text, 2);
// Draw standard deviation markers
for (let i = -3; i <= 3; i++) {
const x = centerX + i * scale;
const label = i === 0 ? 'μ' : (i > 0 ? `+${i}σ` : `${i}σ`);
drawLine(ctx, x, centerY, x, centerY + 10, COLORS.text, 1);
drawText(ctx, label, x, centerY + 25, 12, i === 0 ? '#ffd93d' : COLORS.textSecondary);
}
// Fill regions based on showLevel
const regions = [
{ sigma: 3, color: 'rgba(153, 102, 255, 0.3)', percent: '99.7%', show: showLevel === '3' || showLevel === 'all' },
{ sigma: 2, color: 'rgba(255, 107, 107, 0.4)', percent: '95%', show: showLevel === '2' || showLevel === 'all' },
{ sigma: 1, color: 'rgba(100, 255, 218, 0.5)', percent: '68%', show: showLevel === '1' || showLevel === 'all' }
];
regions.forEach(region => {
if (!region.show) return;
ctx.beginPath();
ctx.fillStyle = region.color;
for (let px = -region.sigma * scale; px <= region.sigma * scale; px++) {
const x = px / scale;
const y = normalPDF(x);
const plotX = centerX + px;
const plotY = centerY - y * height * 2;
if (px === -region.sigma * scale) {
ctx.moveTo(plotX, centerY);
ctx.lineTo(plotX, plotY);
} else {
ctx.lineTo(plotX, plotY);
}
}
ctx.lineTo(centerX + region.sigma * scale, centerY);
ctx.closePath();
ctx.fill();
});
// Draw the curve
ctx.beginPath();
ctx.strokeStyle = 'white';
ctx.lineWidth = 3;
for (let px = -4 * scale; px <= 4 * scale; px++) {
const x = px / scale;
const y = normalPDF(x);
const plotX = centerX + px;
const plotY = centerY - y * height * 2;
if (px === -4 * scale) ctx.moveTo(plotX, plotY);
else ctx.lineTo(plotX, plotY);
}
ctx.stroke();
// Draw percentage labels
const labelY = centerY - height * 0.4;
if (showLevel === '1' || showLevel === 'all') {
drawText(ctx, '68%', centerX, labelY + 60, 24, '#64ffda');
}
if (showLevel === '2' || showLevel === 'all') {
drawText(ctx, '95%', centerX, labelY + 30, 18, '#ff6b6b');
}
if (showLevel === '3' || showLevel === 'all') {
drawText(ctx, '99.7%', centerX, labelY, 14, '#9966ff');
}
// Legend
const legendY = canvas.height - 40;
drawRect(ctx, padding, legendY, 15, 15, 'rgba(100, 255, 218, 0.5)');
drawText(ctx, '±1σ = 68%', padding + 25, legendY + 12, 11, COLORS.text, 'left');
drawRect(ctx, padding + 120, legendY, 15, 15, 'rgba(255, 107, 107, 0.4)');
drawText(ctx, '±2σ = 95%', padding + 145, legendY + 12, 11, COLORS.text, 'left');
drawRect(ctx, padding + 240, legendY, 15, 15, 'rgba(153, 102, 255, 0.3)');
drawText(ctx, '±3σ = 99.7%', padding + 265, legendY + 12, 11, COLORS.text, 'left');
// Example
drawText(ctx, 'Example: IQ (μ=100, σ=15) → 68% between 85-115', canvas.width - padding - 150, legendY + 12, 11, '#ffd93d');
}
const show68Btn = document.getElementById('normalShow68Btn');
const show95Btn = document.getElementById('normalShow95Btn');
const show997Btn = document.getElementById('normalShow997Btn');
const showAllBtn = document.getElementById('normalShowAllBtn');
if (show68Btn) show68Btn.addEventListener('click', () => { showLevel = '1'; draw(); });
if (show95Btn) show95Btn.addEventListener('click', () => { showLevel = '2'; draw(); });
if (show997Btn) show997Btn.addEventListener('click', () => { showLevel = '3'; draw(); });
if (showAllBtn) showAllBtn.addEventListener('click', () => { showLevel = 'all'; draw(); });
draw();
}
// ===== ML-10: DECISION TREE VISUALIZATION =====
function initDecisionTreeVisualization() {
const canvas = document.getElementById('decisionTreeCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let testHeight = 175;
let classifying = false;
let classificationPath = null;
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2;
// Title
drawText(ctx, 'Decision Tree: Is a Person Tall? (Height > 170 cm)', centerX, 30, 18, COLORS.cyan);
// Root node (decision node)
const rootX = centerX, rootY = 100;
const nodeWidth = 180, nodeHeight = 60;
// Draw root node
ctx.fillStyle = classifying ? '#21262d' : '#1a365d';
ctx.strokeStyle = COLORS.cyan;
ctx.lineWidth = 3;
roundRect(ctx, rootX - nodeWidth / 2, rootY - nodeHeight / 2, nodeWidth, nodeHeight, 10, true, true);
drawText(ctx, 'Height > 170?', rootX, rootY - 5, 16, COLORS.cyan);
drawText(ctx, '(Root Node)', rootX, rootY + 15, 11, COLORS.textSecondary);
// Branches
const leafY = 280;
const leftX = centerX - 180;
const rightX = centerX + 180;
// Left branch (NO)
ctx.strokeStyle = classificationPath === 'left' ? '#ff6b6b' : COLORS.text;
ctx.lineWidth = classificationPath === 'left' ? 4 : 2;
ctx.beginPath();
ctx.moveTo(rootX - nodeWidth / 4, rootY + nodeHeight / 2);
ctx.lineTo(leftX, leafY - nodeHeight / 2);
ctx.stroke();
drawText(ctx, 'NO (≤ 170)', leftX + 40, rootY + 80, 14, '#ff6b6b');
// Right branch (YES)
ctx.strokeStyle = classificationPath === 'right' ? '#51cf66' : COLORS.text;
ctx.lineWidth = classificationPath === 'right' ? 4 : 2;
ctx.beginPath();
ctx.moveTo(rootX + nodeWidth / 4, rootY + nodeHeight / 2);
ctx.lineTo(rightX, leafY - nodeHeight / 2);
ctx.stroke();
drawText(ctx, 'YES (> 170)', rightX - 40, rootY + 80, 14, '#51cf66');
// Left leaf node (NOT TALL)
const leafActive = classificationPath === 'left';
ctx.fillStyle = leafActive ? '#4a1c1c' : '#21262d';
ctx.strokeStyle = '#ff6b6b';
ctx.lineWidth = leafActive ? 4 : 2;
roundRect(ctx, leftX - nodeWidth / 2, leafY - nodeHeight / 2, nodeWidth, nodeHeight, 10, true, true);
drawText(ctx, '🔴 Class: 0', leftX, leafY - 8, 16, '#ff6b6b');
drawText(ctx, 'NOT TALL', leftX, leafY + 12, 12, '#ff6b6b');
// Right leaf node (TALL)
const rightActive = classificationPath === 'right';
ctx.fillStyle = rightActive ? '#1c4a1c' : '#21262d';
ctx.strokeStyle = '#51cf66';
ctx.lineWidth = rightActive ? 4 : 2;
roundRect(ctx, rightX - nodeWidth / 2, leafY - nodeHeight / 2, nodeWidth, nodeHeight, 10, true, true);
drawText(ctx, '🟢 Class: 1', rightX, leafY - 8, 16, '#51cf66');
drawText(ctx, 'TALL', rightX, leafY + 12, 12, '#51cf66');
// Show test input
if (classifying) {
const resultText = testHeight > 170 ? `${testHeight} cm → TALL (Class 1)` : `${testHeight} cm → NOT TALL (Class 0)`;
const resultColor = testHeight > 170 ? '#51cf66' : '#ff6b6b';
drawText(ctx, `Test Input: ${testHeight} cm`, centerX, 380, 16, COLORS.text);
drawText(ctx, `Result: ${resultText}`, centerX, 410, 18, resultColor);
}
// Legend
drawText(ctx, '📋 Components: Root Node (Question) → Branches (Yes/No) → Leaf Nodes (Predictions)', centerX, canvas.height - 20, 12, COLORS.textSecondary);
}
function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
if (fill) ctx.fill();
if (stroke) ctx.stroke();
}
const slider = document.getElementById('heightTestSlider');
const label = document.getElementById('heightTestLabel');
const classifyBtn = document.getElementById('treeClassifyBtn');
const resetBtn = document.getElementById('treeResetBtn');
if (slider) {
slider.addEventListener('input', (e) => {
testHeight = parseInt(e.target.value);
if (label) label.textContent = testHeight;
});
}
if (classifyBtn) {
classifyBtn.addEventListener('click', () => {
classifying = true;
classificationPath = testHeight > 170 ? 'right' : 'left';
draw();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
classifying = false;
classificationPath = null;
draw();
});
}
draw();
}
// ===== TOPIC 12: CORRELATION VISUALIZATION =====
function initCorrelationVisualization() {
const canvas = document.getElementById('correlationCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let r = 0.7;
function generateCorrelatedData(rho) {
const data = [];
const n = 50;
for (let i = 0; i < n; i++) {
const x = (Math.random() - 0.5) * 2;
const noise = (Math.random() - 0.5) * 2;
const y = rho * x + Math.sqrt(1 - rho * rho) * noise;
data.push({ x: x * 40 + 50, y: y * 40 + 50 });
}
return data;
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 60, width = canvas.width - padding * 2, height = canvas.height - padding * 2;
const data = generateCorrelatedData(r);
let statusText = '';
let color = '#fff';
if (r > 0.7) { statusText = 'Strong Positive'; color = '#51cf66'; }
else if (r > 0.3) { statusText = 'Moderate Positive'; color = '#64ffda'; }
else if (r > -0.3) { statusText = 'Weak / No Correlation'; color = '#ffd93d'; }
else if (r > -0.7) { statusText = 'Moderate Negative'; color = '#ffa94d'; }
else { statusText = 'Strong Negative'; color = '#ff6b6b'; }
drawText(ctx, `r = ${r.toFixed(2)} (${statusText})`, canvas.width / 2, 30, 20, color);
// Axes
drawLine(ctx, padding, height + padding, width + padding, height + padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, height + padding, COLORS.text, 2);
data.forEach(p => {
const px = padding + (p.x / 100) * width;
const py = padding + height - (p.y / 100) * height;
drawCircle(ctx, px, py, 5, color);
});
drawText(ctx, 'Standardized X', canvas.width / 2, canvas.height - 15, 12, COLORS.textSecondary);
}
const s = document.getElementById('corrSlider'), l = document.getElementById('corrLabel');
if (s) s.addEventListener('input', (e) => {
r = e.target.value / 100;
if (l) l.textContent = r.toFixed(2);
draw();
});
draw();
}
console.log('%c\u2713 Ultimate Learning Platform Fully Initialized', 'color: #51cf66; font-size: 14px; font-weight: bold;');
// ===== TOPIC 10: SKEWNESS VISUALIZATION =====
function initSkewnessVisualization() {
const canvas = document.getElementById('skewnessCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
function normalPDF(x, mean, std) {
return Math.exp(-0.5 * Math.pow((x - mean) / std, 2)) / (std * Math.sqrt(2 * Math.PI));
}
function betaPDF(x, alpha, beta) {
if (x <= 0 || x >= 1) return 0;
const B = (Math.pow(x, alpha - 1) * Math.pow(1 - x, beta - 1));
return B * 3; // Scale for visibility
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 50;
const chartWidth = (canvas.width - padding * 4) / 3;
const chartHeight = canvas.height - 120;
const charts = [
{ type: 'negative', title: 'Negative Skew (Left Skewed)', color: '#ff6b6b', alpha: 5, beta: 2 },
{ type: 'symmetric', title: 'Symmetric (Normal)', color: '#64ffda', mean: 0.5, std: 0.15 },
{ type: 'positive', title: 'Positive Skew (Right Skewed)', color: '#51cf66', alpha: 2, beta: 5 }
];
charts.forEach((chart, idx) => {
const startX = padding + idx * (chartWidth + padding);
const centerY = canvas.height - 40;
drawText(ctx, chart.title, startX + chartWidth / 2, 40, 14, chart.color);
drawLine(ctx, startX, centerY, startX + chartWidth, centerY, COLORS.text, 2);
drawLine(ctx, startX, centerY - chartHeight, startX, centerY, COLORS.text, 2);
ctx.beginPath();
ctx.strokeStyle = chart.color;
ctx.lineWidth = 3;
for (let i = 0; i <= 100; i++) {
const x = i / 100;
let y = chart.type === 'symmetric' ? normalPDF(x, chart.mean, chart.std) : betaPDF(x, chart.alpha, chart.beta);
const px = startX + x * chartWidth;
const py = centerY - y * chartHeight / 3;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
}
ctx.stroke();
let modePos, medianPos, meanPos;
if (chart.type === 'negative') { modePos = 0.75; medianPos = 0.65; meanPos = 0.55; }
else if (chart.type === 'positive') { modePos = 0.25; medianPos = 0.35; meanPos = 0.45; }
else { modePos = medianPos = meanPos = 0.5; }
if (chart.type === 'symmetric') {
const x = startX + 0.5 * chartWidth;
drawLine(ctx, x, centerY, x, centerY - chartHeight * 0.8, '#fff', 1);
drawText(ctx, 'Mean=Median=Mode', x, centerY + 20, 10, '#fff');
} else {
const ann = [
{ pos: modePos, label: 'Mode', color: '#ff6b6b' },
{ pos: medianPos, label: 'Median', color: '#ffd93d' },
{ pos: meanPos, label: 'Mean', color: '#4a90e2' }
];
ann.forEach((a, i) => {
const x = startX + a.pos * chartWidth;
const h = centerY - (chart.type === 'negative' ? betaPDF(a.pos, 5, 2) : betaPDF(a.pos, 2, 5)) * chartHeight / 3;
drawLine(ctx, x, centerY, x, h, a.color, 1);
drawText(ctx, a.label, x, centerY + 15 + (i * 12), 10, a.color);
});
}
});
drawText(ctx, 'Rule: Skew pulls Mean towards the tail!', canvas.width / 2, canvas.height - 10, 12, COLORS.textSecondary);
}
const btn = document.getElementById('skewnessAnimateBtn');
if (btn) btn.addEventListener('click', draw);
draw();
}
// ===== TOPIC 20: PDF VS CDF VISUALIZATION =====
function initPDFCDFVisualization() {
const canvas = document.getElementById('pdfCdfCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let rangeStart = 2, rangeEnd = 6;
function draw() {
clearCanvas(ctx, canvas);
const padding = 60;
const chartWidth = (canvas.width - padding * 3) / 2;
const chartHeight = canvas.height - 150;
const pdfStartX = padding, cdfStartX = padding * 2 + chartWidth, chartStartY = 100;
drawText(ctx, 'PDF: Relative Likelihood (height)', pdfStartX + chartWidth / 2, 50, 16, COLORS.cyan);
drawLine(ctx, pdfStartX, chartStartY + chartHeight, pdfStartX + chartWidth, chartStartY + chartHeight, COLORS.text, 2);
drawLine(ctx, pdfStartX, chartStartY, pdfStartX, chartStartY + chartHeight, COLORS.text, 2);
ctx.fillStyle = 'rgba(100, 255, 218, 0.2)';
ctx.fillRect(pdfStartX, chartStartY + chartHeight * 0.7, chartWidth, chartHeight * 0.3);
ctx.strokeStyle = COLORS.cyan;
ctx.strokeRect(pdfStartX, chartStartY + chartHeight * 0.7, chartWidth, chartHeight * 0.3);
const shadeX1 = pdfStartX + (rangeStart / 10) * chartWidth;
const shadeX2 = pdfStartX + (rangeEnd / 10) * chartWidth;
ctx.fillStyle = 'rgba(255, 107, 107, 0.5)';
ctx.fillRect(shadeX1, chartStartY + chartHeight * 0.7, shadeX2 - shadeX1, chartHeight * 0.3);
drawText(ctx, 'Area = Probability', (shadeX1 + shadeX2) / 2, chartStartY + chartHeight * 0.85, 12, '#ff6b6b');
drawText(ctx, 'CDF: Cumulative Probability (area)', cdfStartX + chartWidth / 2, 50, 16, COLORS.orange);
drawLine(ctx, cdfStartX, chartStartY + chartHeight, cdfStartX + chartWidth, chartStartY + chartHeight, COLORS.text, 2);
drawLine(ctx, cdfStartX, chartStartY, cdfStartX, chartStartY + chartHeight, COLORS.text, 2);
ctx.beginPath();
ctx.strokeStyle = COLORS.orange; ctx.lineWidth = 3;
ctx.moveTo(cdfStartX, chartStartY + chartHeight); ctx.lineTo(cdfStartX + chartWidth, chartStartY);
ctx.stroke();
const cdfX1 = cdfStartX + (rangeStart / 10) * chartWidth;
const cdfY1 = chartStartY + chartHeight - (rangeStart / 10) * chartHeight;
const cdfX2 = cdfStartX + (rangeEnd / 10) * chartWidth;
const cdfY2 = chartStartY + chartHeight - (rangeEnd / 10) * chartHeight;
drawCircle(ctx, cdfX1, cdfY1, 6, '#ffd93d');
drawCircle(ctx, cdfX2, cdfY2, 6, '#ffd93d');
ctx.setLineDash([5, 5]);
drawLine(ctx, cdfX1, cdfY1, cdfX1, chartStartY + chartHeight, '#ffd93d', 1);
drawLine(ctx, cdfX2, cdfY2, cdfX2, chartStartY + chartHeight, '#ffd93d', 1);
ctx.setLineDash([]);
drawText(ctx, `F(${rangeStart}) = ${(rangeStart / 10).toFixed(1)}`, cdfX1, cdfY1 - 10, 10, '#ffd93d');
drawText(ctx, `F(${rangeEnd}) = ${(rangeEnd / 10).toFixed(1)}`, cdfX2, cdfY2 - 10, 10, '#ffd93d');
}
const s1 = document.getElementById('pdfRangeSlider'), s2 = document.getElementById('pdfRangeSlider2'), l = document.getElementById('pdfRangeLabel');
const update = () => { rangeStart = Math.min(s1.value, s2.value); rangeEnd = Math.max(s1.value, s2.value); if (l) l.textContent = `Range: [${rangeStart}, ${rangeEnd}]`; draw(); };
if (s1) s1.addEventListener('input', update); if (s2) s2.addEventListener('input', update);
draw();
}
// ===== TOPIC 24: NORMAL DISTRIBUTION 68-95-99.7 RULE =====
function initNormalRuleVisualization() {
const canvas = document.getElementById('normalRuleCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let showLevel = 'all';
function normalPDF(x) { return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI); }
function draw() {
clearCanvas(ctx, canvas);
const padding = 60, width = canvas.width - padding * 2, height = canvas.height - padding * 2;
const centerX = canvas.width / 2, centerY = padding + height * 0.85, scale = width / 8;
drawText(ctx, 'The 68-95-99.7 Rule (Empirical Rule)', centerX, 25, 18, COLORS.cyan);
drawLine(ctx, padding, centerY, canvas.width - padding, centerY, COLORS.text, 2);
for (let i = -3; i <= 3; i++) {
const x = centerX + i * scale;
const label = i === 0 ? '\u03bc' : (i > 0 ? `+${i}\u03c3` : `${i}\u03c3`);
drawLine(ctx, x, centerY, x, centerY + 10, COLORS.text, 1);
drawText(ctx, label, x, centerY + 25, 12, i === 0 ? '#ffd93d' : COLORS.textSecondary);
}
const regions = [
{ sigma: 3, color: 'rgba(153, 102, 255, 0.3)', show: showLevel === '3' || showLevel === 'all' },
{ sigma: 2, color: 'rgba(255, 107, 107, 0.4)', show: showLevel === '2' || showLevel === 'all' },
{ sigma: 1, color: 'rgba(100, 255, 218, 0.5)', show: showLevel === '1' || showLevel === 'all' }
];
regions.forEach(r => {
if (!r.show) return;
ctx.beginPath(); ctx.fillStyle = r.color;
for (let px = -r.sigma * scale; px <= r.sigma * scale; px++) {
const x = px / scale, y = normalPDF(x);
const plotX = centerX + px, plotY = centerY - y * height * 2;
if (px === -r.sigma * scale) ctx.moveTo(plotX, centerY);
ctx.lineTo(plotX, plotY);
}
ctx.lineTo(centerX + r.sigma * scale, centerY); ctx.closePath(); ctx.fill();
});
ctx.beginPath(); ctx.strokeStyle = 'white'; ctx.lineWidth = 3;
for (let px = -4 * scale; px <= 4 * scale; px++) {
const x = px / scale, y = normalPDF(x);
const plotX = centerX + px, plotY = centerY - y * height * 2;
if (px === -4 * scale) ctx.moveTo(plotX, plotY);
else ctx.lineTo(plotX, plotY);
}
ctx.stroke();
}
const b1 = document.getElementById('normalShow68Btn'), b2 = document.getElementById('normalShow95Btn'), b3 = document.getElementById('normalShow997Btn'), b4 = document.getElementById('normalShowAllBtn');
if (b1) b1.addEventListener('click', () => { showLevel = '1'; draw(); });
if (b2) b2.addEventListener('click', () => { showLevel = '2'; draw(); });
if (b3) b3.addEventListener('click', () => { showLevel = '3'; draw(); });
if (b4) b4.addEventListener('click', () => { showLevel = 'all'; draw(); });
draw();
}
// ===== ML-10: DECISION TREE VISUALIZATION =====
function initDecisionTreeVisualization() {
const canvas = document.getElementById('decisionTreeCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let testHeight = 165, classifying = false, classificationPath = null;
function draw() {
clearCanvas(ctx, canvas);
const centerX = canvas.width / 2, rootY = 80, leafY = 280, leftX = centerX - 180, rightX = centerX + 180;
const nodeWidth = 140, nodeHeight = 60;
drawLine(ctx, centerX, rootY, leftX, leafY, COLORS.textSecondary, 2);
drawLine(ctx, centerX, rootY, rightX, leafY, COLORS.textSecondary, 2);
ctx.fillStyle = '#21262d'; ctx.strokeStyle = COLORS.cyan; ctx.lineWidth = 3;
roundRect(ctx, centerX - nodeWidth / 2, rootY - nodeHeight / 2, nodeWidth, nodeHeight, 10, true, true);
drawText(ctx, 'ROOT NODE: Height > 170?', centerX, rootY + 5, 14, '#fff');
const lActive = classificationPath === 'left', rActive = classificationPath === 'right';
ctx.fillStyle = lActive ? '#4a1c1c' : '#21262d'; ctx.strokeStyle = '#ff6b6b';
roundRect(ctx, leftX - nodeWidth / 2, leafY - nodeHeight / 2, nodeWidth, nodeHeight, 10, true, true);
drawText(ctx, 'Class 0: NOT TALL', leftX, leafY + 5, 14, '#ff6b6b');
ctx.fillStyle = rActive ? '#1c4a1c' : '#21262d'; ctx.strokeStyle = '#51cf66';
roundRect(ctx, rightX - nodeWidth / 2, leafY - nodeHeight / 2, nodeWidth, nodeHeight, 10, true, true);
drawText(ctx, 'Class 1: TALL', rightX, leafY + 5, 14, '#51cf66');
if (classifying) {
drawText(ctx, `Test: ${testHeight} cm \u2192 ${testHeight > 170 ? 'TALL' : 'NOT TALL'}`, centerX, 400, 18, COLORS.cyan);
}
}
function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius); ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height); ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius); ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y); ctx.closePath();
if (fill) ctx.fill(); if (stroke) ctx.stroke();
}
const s = document.getElementById('heightTestSlider'), b = document.getElementById('treeClassifyBtn');
if (s) s.addEventListener('input', (e) => { testHeight = e.target.value; draw(); });
if (b) b.addEventListener('click', () => { classifying = true; classificationPath = testHeight > 170 ? 'right' : 'left'; draw(); });
draw();
}
// ===== TOPIC 11: COVARIANCE VISUALIZATION =====
function initCovarianceVisualization() {
const canvas = document.getElementById('covarianceCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let covType = 'positive';
function generateData(type) {
let data = [];
for (let i = 0; i < 30; i++) {
let x = Math.random() * 80 + 10, y;
if (type === 'positive') y = x + (Math.random() - 0.5) * 30;
else if (type === 'negative') y = 100 - x + (Math.random() - 0.5) * 30;
else y = Math.random() * 80 + 10;
data.push({ x, y });
}
return data;
}
function draw() {
clearCanvas(ctx, canvas);
const padding = 60, width = canvas.width - padding * 2, height = canvas.height - padding * 2;
const data = generateData(covType);
const meanX = data.reduce((s, p) => s + p.x, 0) / data.length;
const meanY = data.reduce((s, p) => s + p.y, 0) / data.length;
const cov = data.reduce((s, p) => s + (p.x - meanX) * (p.y - meanY), 0) / (data.length - 1);
drawText(ctx, `${covType.toUpperCase()} Covariance: ${cov.toFixed(2)}`, canvas.width / 2, 25, 18, COLORS.cyan);
drawLine(ctx, padding, height + padding, width + padding, height + padding, COLORS.text, 2);
drawLine(ctx, padding, padding, padding, height + padding, COLORS.text, 2);
data.forEach(p => {
drawCircle(ctx, padding + (p.x / 100) * width, padding + height - (p.y / 100) * height, 6, COLORS.cyan);
});
}
const b1 = document.getElementById('covPositiveBtn'), b2 = document.getElementById('covNegativeBtn'), b3 = document.getElementById('covZeroBtn');
if (b1) b1.addEventListener('click', () => { covType = 'positive'; draw(); });
if (b2) b2.addEventListener('click', () => { covType = 'negative'; draw(); });
if (b3) b3.addEventListener('click', () => { covType = 'zero'; draw(); });
draw();
} |