In [1]:
import numpy as np
import matplotlib.pyplot as plt
from bussilab import maxent
np.random.seed(1977) # makes test reproducible
In [2]:
data=np.vstack((0.1*np.random.normal(size=(100,2)),np.array((1,2))+0.1*np.random.normal(size=(100,2))))
In [3]:
plt.plot(data[:,0],data[:,1],".")
plt.xlabel("x")
plt.ylabel("y")
plt.show()
No description has been provided for this image
In [4]:
m=maxent.maxent(data,(0.5,1.0))
print(m)
plt.plot(np.exp(m.logW_ME),".")
plt.xlabel("index")
plt.ylabel("weight")
plt.show()
 averages: array([0.49999992, 0.99999548])
    gamma: -0.0011384772610101845
  lambdas: array([-0.42088871,  0.2016774 ])
  logW_ME: array([-5.31888382, -5.27743876, -5.35487613, -5.29703524, -5.27892868,
                  -5.33126286, -5.32806097, -5.28908498, -5.28297505, -5.35772268,
                  -5.31628962, -5.34448691, -5.2996295 , -5.32426905, -5.29128043,
                  -5.35706124, -5.36874151, -5.31924562, -5.36027793, -5.32671717,
                  -5.29138794, -5.28716984, -5.36981818, -5.20552972, -5.33418371,
                  -5.26135867, -5.35234184, -5.24332001, -5.34355672, -5.24304372,
                  -5.26803679, -5.3071542 , -5.29199113, -5.30663888, -5.27902363,
                  -5.31458904, -5.30529954, -5.37312684, -5.27993518, -5.32721081,
                  -5.21622239, -5.29665818, -5.34624208, -5.24937643, -5.35388659,
                  -5.36402559, -5.25554415, -5.40950545, -5.24212836, -5.32796189,
                  -5.33245018, -5.28398617, -5.36458773, -5.34129474, -5.28267197,
                  -5.35642097, -5.30399236, -5.22959433, -5.36798104, -5.36526721,
                  -5.24844131, -5.23934936, -5.32941924, -5.35321741, -5.29690276,
                  -5.3043173 , -5.27708085, -5.32535132, -5.33874957, -5.30750981,
                  -5.27801048, -5.30081391, -5.27230073, -5.25758093, -5.41300584,
                  -5.24995715, -5.25083406, -5.28223417, -5.24640608, -5.343506  ,
                  -5.35273932, -5.35657776, -5.30954497, -5.2450967 , -5.24308899,
                  -5.33747875, -5.31811987, -5.28877192, -5.40592403, -5.23792204,
                  -5.29728414, -5.31247864, -5.27916575, -5.33758661, -5.33359923,
                  -5.360761  , -5.21153856, -5.32145314, -5.24388663, -5.25906232,
                  -5.27290837, -5.34123976, -5.26663274, -5.3274194 , -5.27322373,
                  -5.31648718, -5.29002146, -5.42337626, -5.32275601, -5.28078701,
                  -5.31164246, -5.24471182, -5.33271325, -5.36643516, -5.34018482,
                  -5.20727401, -5.26099222, -5.25509831, -5.31813669, -5.20416471,
                  -5.29652076, -5.30588083, -5.29226974, -5.32051365, -5.29355995,
                  -5.34994269, -5.19973507, -5.23991285, -5.3294956 , -5.32944852,
                  -5.23745545, -5.29130465, -5.28902337, -5.2531201 , -5.1992568 ,
                  -5.19863805, -5.30929803, -5.15819861, -5.3334149 , -5.34913654,
                  -5.39113272, -5.2461611 , -5.27525901, -5.2524737 , -5.21942722,
                  -5.24813461, -5.19656369, -5.31551829, -5.2900877 , -5.33485294,
                  -5.26500359, -5.31149996, -5.34814497, -5.40554895, -5.27634771,
                  -5.2625403 , -5.27336201, -5.26870578, -5.32982245, -5.27566075,
                  -5.31153037, -5.3182879 , -5.40275171, -5.32137658, -5.23447767,
                  -5.23760609, -5.31270262, -5.29422764, -5.31674062, -5.2474326 ,
                  -5.27595973, -5.37292867, -5.32074291, -5.30421289, -5.26704259,
                  -5.26948648, -5.19902616, -5.24392108, -5.28719961, -5.24464249,
                  -5.31945567, -5.33622251, -5.28571976, -5.29855652, -5.28509204,
                  -5.3186485 , -5.29215876, -5.31909346, -5.28645553, -5.3063736 ,
                  -5.27723529, -5.31482258, -5.3489682 , -5.32658054, -5.36645075,
                  -5.30075003, -5.34800176, -5.25885035, -5.28815326, -5.24676959])
  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
     nfev: 10
      nit: 7
  success: True
No description has been provided for this image
In [5]:
m=maxent.maxent(data,(1.0,2.0))
print(m)
plt.plot(np.exp(m.logW_ME),".")
plt.xlabel("index")
plt.ylabel("weight")
plt.show()
 averages: array([1.00000101, 2.00000031])
    gamma: -0.673025651834692
  lambdas: array([-1.25021236, -1.80626266])
  logW_ME: array([ -9.50986859,  -9.3960107 ,  -9.61071129,  -9.47734274,
                   -9.51346957,  -9.5550503 ,  -9.61042006,  -9.25348623,
                   -9.38042091,  -9.47605797,  -9.91391207,  -9.71537817,
                   -9.30811073,  -9.56869753,  -9.36669442,  -9.82551631,
                   -9.56375321,  -9.61150015,  -9.39671655,  -9.21847531,
                   -9.20012138,  -9.60385814,  -9.66660076,  -9.27135046,
                   -9.59826511,  -9.37188862,  -9.34505469,  -9.42114952,
                   -9.28253432,  -9.19693476,  -9.44227007, -10.13492341,
                   -9.55765972,  -9.75831469,  -9.46112163,  -9.49735041,
                   -9.47291903,  -9.55302465,  -9.9514755 ,  -9.46026578,
                   -9.34797088,  -9.65012159,  -9.66935784,  -9.56560069,
                   -9.65067293,  -9.56681941,  -9.08147313,  -9.68782953,
                   -9.26029013,  -9.41049756,  -9.78776209,  -9.65810795,
                   -9.8583901 ,  -9.92676652,  -9.66268435,  -9.87975735,
                   -9.490421  ,  -9.45794716,  -9.76611923,  -9.48561935,
                   -9.35372173,  -9.43812684,  -9.18467587,  -9.69574268,
                   -9.41915946,  -9.60568416,  -9.46569383,  -9.55997226,
                  -10.02944972,  -9.43674099,  -9.1157442 ,  -9.29221084,
                   -9.50877413,  -9.72230032,  -9.45909051,  -9.51872646,
                   -9.59072582,  -9.47748987,  -9.36858619,  -9.96897724,
                   -9.29676839,  -9.36732114,  -9.72648925,  -9.30599864,
                   -9.53854888,  -9.66288323,  -9.6595068 ,  -9.40392405,
                   -9.43323001,  -9.4095455 ,  -9.26155849,  -9.602827  ,
                   -9.63483552,  -9.38896014,  -9.51324773,  -9.24814926,
                   -9.10434096,  -9.85324266,  -9.35071581,  -9.56819752,
                   -4.38737131,  -4.78560483,  -4.7733354 ,  -4.35550696,
                   -4.75452083,  -4.79395112,  -4.64761375,  -4.57963538,
                   -4.52970162,  -4.99375176,  -4.65398103,  -4.89659338,
                   -4.62652897,  -4.69500536,  -4.48349449,  -4.33587785,
                   -4.50380956,  -4.46917379,  -4.36918166,  -4.88775977,
                   -4.59172498,  -4.89957512,  -4.93501462,  -4.65105752,
                   -4.40760297,  -4.49193598,  -4.63326778,  -4.70869999,
                   -4.88513828,  -4.17512039,  -4.7271367 ,  -4.55357505,
                   -4.72426641,  -4.71076905,  -4.46578738,  -4.26512505,
                   -4.48950604,  -4.14751746,  -4.67207822,  -4.45430764,
                   -4.92928975,  -4.58875719,  -4.4247097 ,  -4.34703264,
                   -4.26737901,  -4.57787019,  -4.89961464,  -4.68682043,
                   -4.66088956,  -4.58319565,  -4.58792246,  -4.83607152,
                   -4.5769083 ,  -4.91394385,  -4.84999715,  -4.46120327,
                   -4.63575898,  -4.57158163,  -4.79453366,  -4.56584765,
                   -5.11328855,  -4.48323004,  -4.7332782 ,  -4.8108067 ,
                   -4.25542014,  -4.11523876,  -4.79331297,  -4.62612838,
                   -4.75139246,  -4.41154548,  -4.5965896 ,  -4.99649962,
                   -4.97378284,  -4.85038912,  -4.49721182,  -4.56364746,
                   -4.43907055,  -4.29348441,  -4.65086569,  -4.3265591 ,
                   -4.57064511,  -5.18924547,  -4.42697962,  -4.84600207,
                   -4.87766057,  -4.83904333,  -4.54150451,  -4.70894444,
                   -4.84695203,  -4.52613267,  -4.33349525,  -4.72207538,
                   -4.51882422,  -4.50357088,  -4.90750365,  -5.02290926,
                   -4.66664818,  -4.77757   ,  -4.90762321,  -4.78912166])
  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
     nfev: 12
      nit: 11
  success: True
No description has been provided for this image
In [6]:
m=maxent.maxent(data,(1.5,1.5),l2=1e-10)
print(m)
plt.plot(np.exp(m.logW_ME),".")
plt.xlabel("index")
plt.ylabel("weight")
plt.show()
 averages: array([1.32553618, 2.03414072])
    gamma: -821480415.3322978
  lambdas: array([-3.57625796e+09,  1.90775698e+09])
  logW_ME: array([-9.71085157e+08, -6.18183169e+08, -1.27739878e+09, -7.82826815e+08,
                  -6.21720621e+08, -1.07559007e+09, -1.04314777e+09, -7.31434415e+08,
                  -6.67809907e+08, -1.31313514e+09, -9.15812497e+08, -1.17818479e+09,
                  -8.19149668e+08, -1.01338625e+09, -7.41478866e+08, -1.27915361e+09,
                  -1.40232542e+09, -9.66043999e+08, -1.34186265e+09, -1.06303905e+09,
                  -7.55861330e+08, -6.86426021e+08, -1.40343161e+09, -6.33142948e+00,
                  -1.09762088e+09, -4.79643883e+08, -1.27669721e+09, -3.18070914e+08,
                  -1.20499034e+09, -3.33752168e+08, -5.32308177e+08, -8.18163035e+08,
                  -7.32276290e+08, -8.44054837e+08, -6.26774868e+08, -9.34573438e+08,
                  -8.55386091e+08, -1.44150430e+09, -5.95165112e+08, -1.04783827e+09,
                  -8.72344485e+07, -7.65588606e+08, -1.19723313e+09, -3.59325903e+08,
                  -1.26552844e+09, -1.36087664e+09, -4.52282284e+08, -1.74845197e+09,
                  -3.20641937e+08, -1.05841670e+09, -1.06718246e+09, -6.54233238e+08,
                  -1.34225682e+09, -1.13323599e+09, -6.42382218e+08, -1.26918232e+09,
                  -8.42553292e+08, -1.95184818e+08, -1.37934968e+09, -1.37827738e+09,
                  -3.68255624e+08, -2.82010648e+08, -1.08937378e+09, -1.25604471e+09,
                  -7.86365014e+08, -8.36089886e+08, -6.09432528e+08, -1.02354579e+09,
                  -1.10271281e+09, -8.77616138e+08, -6.45796797e+08, -8.30780673e+08,
                  -5.64193577e+08, -4.18359385e+08, -1.79749387e+09, -3.68182456e+08,
                  -3.70033046e+08, -6.53503249e+08, -3.49274903e+08, -1.14914843e+09,
                  -1.28406677e+09, -1.31190791e+09, -8.72012725e+08, -3.42886398e+08,
                  -3.06577992e+08, -1.12119354e+09, -9.52334320e+08, -7.16558321e+08,
                  -1.73770963e+09, -2.71847310e+08, -8.02416101e+08, -9.07623241e+08,
                  -6.13997144e+08, -1.14424264e+09, -1.09937575e+09, -1.35807305e+09,
                  -6.59755177e+07, -9.65820626e+08, -3.28705632e+08, -4.43738515e+08,
                  -9.82821244e+08, -1.54766921e+09, -8.96844291e+08, -1.46163638e+09,
                  -9.55945878e+08, -1.33074109e+09, -1.11132956e+09, -2.28188926e+09,
                  -1.40683572e+09, -1.00271662e+09, -1.29971073e+09, -6.95381588e+08,
                  -1.48601418e+09, -1.77510425e+09, -1.56283415e+09, -4.13552821e+08,
                  -8.69316950e+08, -8.20619211e+08, -1.37943303e+09, -3.41848815e+08,
                  -1.17262210e+09, -1.22955291e+09, -1.10777749e+09, -1.37745103e+09,
                  -1.16161397e+09, -1.64740393e+09, -3.23687199e+08, -6.68618484e+08,
                  -1.43703185e+09, -1.49392205e+09, -6.45661129e+08, -1.13012962e+09,
                  -1.09642342e+09, -7.83838560e+08, -3.33025105e+08, -3.43813584e+08,
                  -1.29250210e+09, -1.78110600e-03, -1.48846830e+09, -1.64339766e+09,
                  -1.97197035e+09, -7.32887093e+08, -1.00034458e+09, -8.07546255e+08,
                  -5.25259314e+08, -7.51007569e+08, -2.74484620e+08, -1.33092221e+09,
                  -1.11083683e+09, -1.50820512e+09, -8.97574613e+08, -1.28377024e+09,
                  -1.62484028e+09, -2.09915833e+09, -9.75533665e+08, -8.86280531e+08,
                  -9.66738586e+08, -9.31238175e+08, -1.44719962e+09, -9.92463974e+08,
                  -1.26166338e+09, -1.37154985e+09, -2.08930027e+09, -1.37209777e+09,
                  -6.57714861e+08, -6.96359960e+08, -1.29772827e+09, -1.14981137e+09,
                  -1.33638996e+09, -7.58297533e+08, -9.92595114e+08, -1.80750385e+09,
                  -1.35340871e+09, -1.21895019e+09, -9.22709415e+08, -9.38699192e+08,
                  -3.33166195e+08, -7.37146656e+08, -1.08641362e+09, -7.40780018e+08,
                  -1.37469752e+09, -1.47125973e+09, -1.09155327e+09, -1.16988654e+09,
                  -1.04969722e+09, -1.34598468e+09, -1.13856583e+09, -1.36037168e+09,
                  -1.06408781e+09, -1.26399644e+09, -1.02497198e+09, -1.32199879e+09,
                  -1.63672019e+09, -1.44235812e+09, -1.75809090e+09, -1.17477332e+09,
                  -1.61634670e+09, -8.28510630e+08, -1.07402392e+09, -7.22033011e+08])
  message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
     nfev: 98
      nit: 24
  success: True
No description has been provided for this image
In [ ]: