genann/my_test.c

77 lines
12 KiB
C

/** function comment
* @Author: 陈逸凡 1343619937@qq.com
* @Date: 2024-04-25 15:21:22
* @LastEditors: 陈逸凡 1343619937@qq.com
* @LastEditTime: 2024-04-25 16:06:42
* @FilePath: \genann-master\my_test.c
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "genann.h"
/*
上面3组是吸到了
下面3组是没吸到
*/
const double input[][300]={
{2304,2288,2305,2337,2361,2354,2302,2220,2146,2095,2067,2068,2097,2141,2161,2113,1986,1821,1696,1626,1587,1570,1571,1547,1462,1358,1296,1257,1183,1093,1045,1024,1008,1019,1027,949,775,609,508,467,479,525,587,641,652,585,504,490,530,553,573,650,737,765,772,790,742,622,546,555,594,672,774,823,786,731,701,693,703,729,769,842,947,1035,1064,1042,1005,976,966,985,1045,1148,1266,1339,1332,1282,1242,1243,1274,1320,1373,1460,1577,1664,1677,1634,1576,1536,1514,1518,1570,1665,1765,1812,1795,1726,1661,1635,1631,1630,1643,1693,1765,1806,1782,1692,1583,1488,1415,1379,1385,1442,1508,1530,1489,1406,1327,1290,1283,1280,1293,1347,1429,1489,1488,1416,1312,1219,1160,1135,1158,1230,1324,1387,1379,1317,1249,1216,1214,1232,1269,1348,1458,1551,1574,1520,1422,1342,1296,1285,1324,1416,1526,1586,1576,1505,1435,1409,1416,1435,1474,1547,1643,1706,1695,1611,1510,1437,1398,1395,1429,1504,1579,1601,1552,1464,1389,1363,1369,1375,1392,1455,1550,1623,1626,1550,1439,1336,1264,1234,1262,1350,1468,1559,1574,1536,1502,1519,1583,1674,1773,1876,1970,2052,2102,2123,2148,2198,2267,2359,2467,2552,2605,2660,2701,2706,2750,2854,2920,2932,3000,3103,3127,3089,3116,3199,3235,3240,3271,3316,3356,3383,3374,3336,3300,3281,3285,3318,3328,3290,3269,3277,3236,3157,3129,3156,3171,3160,3136,3104,3080,3062,3028,2995,},
{2317,2296,2305,2343,2379,2390,2361,2286,2196,2123,2084,2082,2114,2162,2191,2169,2063,1909,1775,1695,1657,1629,1613,1608,1571,1470,1360,1293,1248,1172,1096,1067,1066,1061,1063,1037,917,727,564,494,492,538,597,648,684,673,595,518,522,573,600,635,732,823,834,821,815,741,621,575,616,676,767,875,905,848,779,745,737,753,795,850,932,1038,1103,1097,1034,973,941,943,984,1064,1177,1281,1325,1290,1216,1169,1175,1218,1275,1348,1455,1570,1636,1627,1564,1495,1455,1456,1494,1572,1676,1767,1800,1764,1687,1626,1610,1618,1631,1661,1726,1799,1825,1772,1661,1542,1461,1419,1413,1442,1504,1563,1565,1507,1417,1339,1312,1316,1326,1349,1412,1492,1530,1499,1397,1282,1204,1171,1182,1233,1321,1411,1455,1428,1351,1289,1275,1297,1333,1390,1490,1605,1678,1667,1579,1470,1396,1379,1401,1466,1570,1670,1711,1669,1580,1512,1499,1519,1552,1607,1691,1780,1822,1777,1666,1552,1491,1477,1500,1553,1631,1697,1694,1622,1519,1440,1423,1440,1462,1501,1583,1686,1735,1694,1571,1440,1345,1298,1306,1367,1477,1596,1666,1656,1597,1561,1585,1662,1759,1867,1977,2069,2141,2185,2201,2225,2280,2356,2455,2575,2657,2698,2744,2783,2790,2835,2943,3010,3031,3106,3199,3208,3163,3188,3255,3278,3274,3290,3322,3351,3360,3330,3271,3222,3193,3194,3223,3222,3175,3157,3165,3115,3037,3023,3061,3075,3063,3041,3014,2995,2982,2952,2928,},
{2323,2303,2309,2339,2378,2397,2375,2310,2216,2141,2110,2126,2174,2227,2251,2224,2138,1998,1857,1778,1752,1733,1702,1664,1615,1530,1410,1308,1265,1231,1164,1120,1124,1123,1089,1036,931,757,586,508,530,588,647,681,681,653,590,507,475,531,608,658,730,829,870,813,745,688,596,522,564,670,768,857,909,860,754,682,674,706,764,838,914,999,1061,1047,965,875,843,876,947,1045,1150,1246,1298,1280,1213,1152,1160,1230,1321,1401,1479,1572,1634,1621,1549,1470,1445,1486,1571,1661,1744,1814,1838,1807,1744,1694,1695,1743,1793,1832,1877,1923,1936,1881,1768,1652,1587,1585,1613,1644,1666,1678,1662,1600,1520,1459,1446,1472,1497,1509,1532,1574,1596,1560,1470,1362,1294,1295,1331,1373,1406,1430,1434,1400,1334,1275,1271,1313,1364,1411,1467,1541,1590,1574,1491,1380,1314,1323,1387,1461,1533,1601,1626,1590,1513,1447,1439,1488,1546,1601,1673,1754,1802,1773,1662,1531,1452,1453,1508,1581,1651,1703,1710,1649,1550,1468,1452,1496,1555,1606,1658,1715,1737,1682,1569,1451,1392,1409,1461,1524,1578,1619,1638,1614,1563,1536,1588,1700,1819,1909,1976,2025,2067,2119,2170,2217,2278,2353,2433,2521,2612,2660,2681,2728,2768,2791,2870,2989,3037,3050,3119,3179,3155,3129,3197,3279,3302,3303,3319,3335,3343,3338,3305,3256,3220,3205,3222,3248,3232,3185,3175,3169,3108,3046,3056,3093,3100,3083,3055,3026,3009,2990,2960,2952,},
{1861,1879,1921,1981,2054,2120,2154,2135,2060,1963,1906,1916,1991,2086,2156,2185,2188,2168,2129,2081,2035,1981,1891,1755,1609,1498,1419,1335,1252,1205,1170,1108,1045,1015,979,862,706,591,525,488,497,532,516,434,356,336,340,340,330,318,324,350,363,370,417,481,501,506,560,616,607,595,643,681,659,667,727,758,772,816,849,858,895,957,977,929,828,719,673,731,826,889,913,924,941,954,958,967,1002,1060,1122,1189,1259,1330,1383,1378,1317,1255,1260,1341,1436,1499,1523,1533,1550,1574,1596,1617,1652,1701,1745,1784,1827,1864,1867,1801,1668,1531,1477,1509,1572,1612,1605,1565,1525,1483,1436,1398,1387,1408,1433,1451,1464,1475,1471,1426,1335,1245,1207,1233,1274,1291,1270,1236,1224,1233,1240,1243,1255,1278,1307,1352,1407,1462,1492,1457,1365,1269,1236,1288,1376,1442,1458,1450,1444,1438,1422,1408,1423,1470,1526,1578,1626,1665,1678,1628,1516,1398,1354,1394,1473,1526,1525,1497,1475,1454,1429,1412,1418,1450,1484,1508,1524,1539,1539,1495,1407,1322,1293,1336,1393,1416,1394,1363,1355,1357,1352,1353,1381,1434,1486,1517,1534,1569,1648,1749,1831,1898,1956,2009,2076,2150,2204,2250,2311,2383,2471,2572,2642,2682,2739,2807,2844,2901,3012,3080,3073,3097,3161,3166,3121,3136,3194,3202,3168,3134,3100,3076,3061,3031,2985,2943,2909,2891,2903,2897,2841,2805,2817,2794,2722,2685,2702,2707,2692,2678,2660,2646,2642,2627,2611,},
{1817,1797,1827,1894,1993,2101,2179,2199,2139,2026,1922,1873,1900,1980,2075,2155,2222,2274,2297,2276,2209,2121,2027,1926,1801,1659,1537,1460,1403,1337,1290,1288,1287,1227,1112,976,830,677,558,541,586,611,616,603,529,407,313,290,300,312,319,337,388,444,452,412,400,427,439,457,542,627,619,595,635,674,671,703,774,806,821,861,879,852,831,843,855,854,848,832,832,860,876,862,850,874,926,974,989,982,1013,1098,1195,1274,1307,1291,1244,1197,1169,1192,1284,1407,1493,1519,1509,1507,1534,1567,1591,1616,1664,1741,1818,1853,1835,1773,1695,1622,1570,1559,1598,1653,1659,1610,1540,1494,1491,1500,1486,1458,1452,1488,1538,1570,1548,1475,1380,1280,1207,1185,1226,1299,1346,1335,1287,1249,1241,1246,1250,1257,1289,1348,1412,1450,1437,1387,1339,1307,1285,1296,1356,1424,1450,1428,1389,1372,1402,1445,1465,1466,1486,1547,1623,1664,1651,1590,1516,1448,1402,1399,1448,1522,1558,1537,1482,1436,1433,1445,1437,1424,1448,1516,1586,1618,1584,1500,1404,1318,1269,1273,1333,1417,1460,1438,1373,1327,1325,1347,1365,1378,1405,1448,1479,1492,1514,1572,1678,1783,1852,1897,1931,1966,2028,2113,2182,2246,2330,2413,2491,2576,2635,2668,2723,2787,2826,2887,2993,3060,3052,3073,3141,3157,3115,3127,3184,3186,3140,3104,3079,3065,3064,3048,3007,2966,2927,2907,2913,2899,2844,2818,2837,2818,2751,2716,2730,2736,2722,2703,2682,2665,2658,2641,2623,},
{1822,1808,1846,1923,2033,2137,2203,2202,2125,2003,1893,1839,1841,1865,1873,1863,1855,1842,1794,1714,1632,1565,1477,1348,1230,1146,1064,967,891,881,914,926,917,903,826,668,505,396,318,284,329,422,496,510,472,420,398,396,381,378,437,527,569,586,625,627,554,519,585,649,661,681,701,678,659,690,725,741,770,814,837,826,789,733,693,693,695,681,681,713,763,800,812,817,859,937,1006,1040,1060,1095,1162,1257,1357,1448,1515,1542,1511,1458,1438,1491,1596,1690,1743,1756,1763,1779,1784,1776,1771,1792,1837,1881,1903,1891,1853,1783,1684,1588,1532,1541,1591,1618,1581,1504,1435,1394,1363,1329,1291,1270,1282,1307,1323,1318,1283,1216,1115,1012,955,972,1054,1134,1165,1155,1147,1157,1173,1189,1209,1250,1324,1401,1449,1469,1476,1464,1424,1385,1378,1424,1505,1564,1567,1538,1526,1552,1584,1597,1597,1614,1661,1720,1765,1776,1757,1698,1600,1490,1412,1407,1459,1505,1493,1441,1389,1352,1318,1277,1241,1243,1299,1374,1424,1439,1417,1356,1258,1157,1116,1162,1271,1361,1390,1369,1354,1369,1397,1435,1497,1590,1708,1802,1852,1892,1948,2030,2151,2279,2370,2425,2465,2498,2548,2622,2687,2747,2835,2911,2937,2978,3058,3084,3049,3070,3134,3125,3061,3056,3092,3076,3032,3008,2996,2987,2972,2927,2864,2808,2764,2748,2770,2769,2723,2707,2725,2692,2619,2594,2625,2646,2647,2647,2645,2645,2651,2650,2658,},
//{},
};
//额外找的没吸到
const double test[300]={
1949,1920,1926,1984,2069,2140,2169,2146,2081,2008,1970,1973,2007,2042,2042,2009,1966,1926,1887,1835,1760,1681,1616,1543,1435,1313,1219,1141,1046,962,944,990,1007,951,860,743,602,492,457,456,437,423,442,453,429,394,368,372,402,418,407,431,490,504,465,466,512,529,539,609,679,663,625,623,614,610,662,713,707,691,726,789,841,850,796,712,649,614,591,591,631,703,771,802,813,835,885,940,979,1011,1075,1187,1308,1380,1389,1362,1352,1368,1400,1452,1530,1621,1680,1692,1668,1658,1687,1726,1746,1761,1801,1879,1949,1952,1872,1758,1654,1578,1538,1529,1550,1588,1596,1548,1467,1398,1370,1364,1353,1341,1349,1386,1418,1394,1310,1216,1160,1139,1139,1155,1181,1209,1213,1177,1123,1095,1117,1162,1196,1209,1241,1319,1405,1436,1401,1330,1276,1251,1245,1263,1311,1382,1433,1441,1413,1392,1400,1415,1413,1401,1419,1496,1575,1586,1510,1401,1309,1250,1225,1226,1266,1333,1375,1357,1303,1259,1258,1284,1310,1333,1379,1459,1528,1526,1451,1358,1297,1270,1266,1284,1322,1372,1398,1375,1327,1307,1349,1426,1497,1542,1587,1651,1722,1777,1828,1893,1973,2072,2167,2220,2246,2271,2297,2334,2408,2491,2550,2610,2677,2715,2748,2833,2907,2910,2927,3004,3041,2994,2970,3014,3042,3019,2991,2974,2959,2943,2907,2850,2794,2756,2739,2752,2767,2740,2710,2722,2712,2644,2596,2611,2628,2618,2599,2577,2559,2552,2537,2521,
};
//源数据input[0]数据裁剪了一下
const double test2[300]= {1821,1696,1626,1587,1570,1571,1547,1462,1358,1296,1257,1183,1093,1045,1024,1008,1019,1027,949,775,609,508,467,479,525,587,641,652,585,504,490,530,553,573,650,737,765,772,790,742,622,546,555,594,672,774,823,786,731,701,693,703,729,769,842,947,1035,1064,1042,1005,976,966,985,1045,1148,1266,1339,1332,1282,1242,1243,1274,1320,1373,1460,1577,1664,1677,1634,1576,1536,1514,1518,1570,1665,1765,1812,1795,1726,1661,1635,1631,1630,1643,1693,1765,1806,1782,1692,1583,1488,1415,1379,1385,1442,1508,1530,1489,1406,1327,1290,1283,1280,1293,1347,1429,1489,1488,1416,1312,1219,1160,1135,1158,1230,1324,1387,1379,1317,1249,1216,1214,1232,1269,1348,1458,1551,1574,1520,1422,1342,1296,1285,1324,1416,1526,1586,1576,1505,1435,1409,1416,1435,1474,1547,1643,1706,1695,1611,1510,1437,1398,1395,1429,1504,1579,1601,1552,1464,1389,1363,1369,1375,1392,1455,1550,1623,1626,1550,1439,1336,1264,1234,1262,1350,1468,1559,1574,1536,1502,1519,1583,1674,1773,1876,1970,2052,2102,2123,2148,2198,2267,2359,2467,2552,2605,2660,2701,2706,2750,2854,2920,2932,3000,3103,3127,3089,3116,3199,3235,3240,3271,3316,3356,3383,3374,3336,3300,3281,3285,3318,3328,3290,3269,3277,3236,3157,3129,3156,3171,3160,3136,3104,3080,3062,3028,2995,
};
//目标结果
const double output[]={
1,1,1,
0,0,0,
};
int main(int argc, char *argv[])
{
printf("GENANN example 1.\n");
printf("Train a small ANN to the XOR function using backpropagation.\n");
/* This will make the neural network initialize differently each run. */
/* If you don't get a good result, try again for a different result. */
// srand(time(0));
/* Input and expected out data for the XOR function. */
// const double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
// const double output[4] = {0, 1, 1, 0};
int i;
/* New network with 2 inputs,
* 1 hidden layer of 2 neurons,
* and 1 output. */
genann *ann = genann_init(300, 1, 20, 1);
/* Train on the four labeled data points many times. */
for (i = 0; i < 500; ++i) {
genann_train(ann, input[0], output + 0, 3);
genann_train(ann, input[1], output + 1, 3);
genann_train(ann, input[2], output + 2, 3);
genann_train(ann, input[3], output + 3, 3);
genann_train(ann, input[4], output + 4, 3);
genann_train(ann, input[5], output + 5, 3);
}
/* Run the network and see what it predicts. */
printf("%f\n",*genann_run(ann, input[0]));
printf("%f\n",*genann_run(ann, input[4]));
printf("%f\n",*genann_run(ann, test));
printf("%f\n",*genann_run(ann, test2));
genann_free(ann);
return 0;
}