Skip to content

Commit 9f22eff

Browse files
committed
Add symbolic regression example
1 parent 73786d5 commit 9f22eff

File tree

3 files changed

+861
-0
lines changed

3 files changed

+861
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import numpy as np
5+
6+
7+
def create_data(n: int, t_max: float, a: float, b: float, sigma: float) -> tuple[np.ndarray, np.ndarray]:
8+
t = np.linspace(0.0, t_max, n) + np.random.normal(scale=sigma, size=n)
9+
t[0] = 0.0
10+
x = a + b*np.sqrt(t) + np.random.normal(scale=sigma, size=n)
11+
return t, x
12+
13+
14+
def main():
15+
arg_parser = argparse.ArgumentParser(description='create noisy data set for a + b*sqrt(t)')
16+
arg_parser.add_argument('--n', type=int, default=100,
17+
help='number of points')
18+
arg_parser.add_argument('--t_max', type=float, default=30.0,
19+
help='maximum time')
20+
arg_parser.add_argument('--a', type=float, default=0.1,
21+
help='additive constant')
22+
arg_parser.add_argument('--b', type=float, default=0.5,
23+
help='multiplication factor')
24+
arg_parser.add_argument('--sigma', type=float, default=0.0,
25+
help='noise level')
26+
args = arg_parser.parse_args()
27+
28+
for t, x in zip(*create_data(n=args.n, t_max=args.t_max, a=args.a, b=args.b, sigma=args.sigma)):
29+
print(f'{t},{x}')
30+
31+
if __name__ == '__main__':
32+
main()
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
0.0,3.135792512413561
2+
0.04917507892521977,4.130354853733771
3+
0.38618397131377363,6.011067338531955
4+
0.3870133583739641,6.106184778902891
5+
0.7378723724895282,7.1722800673270966
6+
1.1083426898155673,8.25966345547244
7+
1.2965788974680286,8.754811817195248
8+
1.4664233095930943,9.024385334346336
9+
1.5567002255835847,9.140986767197862
10+
1.8805196710437433,9.86619642295168
11+
2.0403597484700136,10.183508718331238
12+
2.3880881183941485,10.720398260938284
13+
2.4404250954405926,10.762684435660642
14+
2.6093034588740007,11.089069692568328
15+
2.9903586429226374,11.809023895570325
16+
2.9319554439200126,11.492913194979257
17+
3.358514343416962,12.057295084737861
18+
3.463517627451456,12.185740397323244
19+
3.6503835099073654,12.717240550322568
20+
3.945825062960219,12.714905565999084
21+
4.140040738231665,13.238343742055978
22+
4.386959736676804,13.327826099430586
23+
4.571617086388203,13.72517932654574
24+
4.511110955419059,13.576192576128978
25+
4.8587757464378845,14.187086003381816
26+
5.101462904742424,14.406261191423873
27+
5.16555808652569,14.426383357760189
28+
5.430068339408772,14.529098652708946
29+
5.657757527774882,14.858290701837948
30+
5.902811659978236,15.044675412237089
31+
6.166886076950506,15.422188748780993
32+
6.077024895183746,15.164130636336493
33+
6.457555303195658,15.873068343918764
34+
6.670483139183774,15.799814154514008
35+
6.9349296999444725,16.133136042821537
36+
7.015670231413422,16.187639136111635
37+
7.053422373700981,16.183005526440013
38+
7.561850598673937,16.841619753513182
39+
7.5427949470946904,16.705985326188273
40+
7.846026776337292,17.01475047149082
41+
8.047323586909567,17.321619088060434
42+
8.449032560554086,17.430555610924777
43+
8.63280050792723,17.674342431080316
44+
8.651316710079197,17.86229565451557
45+
8.880416160966892,17.89130895746749
46+
8.961370090868897,18.01643142603243
47+
9.23635003920086,18.237081083268915
48+
9.408204030795556,18.362631806349274
49+
9.888658949654786,18.715292300715763
50+
9.757113151921999,18.446579392298386
51+
10.109408563570906,18.880702015074988
52+
10.267726986172564,19.147258680877094
53+
10.408741182428452,19.21668586221017
54+
10.767242128572184,19.426233750601277
55+
10.987099300762203,19.465720488657468
56+
11.148408093570783,19.618631014406855
57+
11.27762457753493,19.703681137156945
58+
11.52800497870441,19.920494671550465
59+
11.851678441109593,20.22533563427639
60+
12.055434662418023,20.335580704918687
61+
12.16874006014594,20.39983531037478
62+
12.202677676417574,20.39100995525543
63+
12.57024556172086,20.73619431865826
64+
12.606423573707934,20.700608692958273
65+
12.949081834064543,20.947785946603847
66+
13.214885791532037,21.276328240212482
67+
13.322979390916037,21.10871625276234
68+
13.625065589473602,21.391931503050813
69+
13.61447718715026,21.499661848556293
70+
13.782406055579965,21.571357507857144
71+
14.036286845447481,21.711368482874757
72+
14.341624764400732,21.748998351391375
73+
14.727438548026752,22.224193240741325
74+
14.649349056101203,22.06921676629916
75+
14.79729748379505,22.162070303714877
76+
15.172483223639146,22.332950462006693
77+
15.459180925022874,22.781678470794308
78+
15.543245773808717,22.893850930939387
79+
15.758482487249992,22.921799711637334
80+
15.86459513416048,22.75209350666247
81+
16.1956978570662,23.087753735311708
82+
16.24674748635097,23.401965639250722
83+
16.47384235930462,23.126800791150767
84+
16.78745969414955,23.56585310475394
85+
17.016115686136974,23.7533250657291
86+
16.97545954714283,23.487108147748426
87+
17.37206351448937,24.034121949776974
88+
17.73197263660408,24.10815489854129
89+
17.83020724040754,24.302119531279345
90+
17.908872587346675,24.128949627545918
91+
18.258436044287723,24.48187135131471
92+
18.290107701344205,24.53318590092017
93+
18.67462077271872,24.563537765146684
94+
18.53875882369785,24.48682113634027
95+
18.86242140013619,24.60026258893294
96+
19.250508467945654,24.845662570850287
97+
19.411781796757236,25.041372568062297
98+
19.686134796254237,25.094581620443236
99+
19.776467086699082,25.316712678356666
100+
19.87362597262397,25.36544920372383

0 commit comments

Comments
 (0)