Vacuum Neutrino Oscillations

Here is a notebook for homogeneous gas model.

Here we are talking about a homogeneous gas bulk of neutrinos with single energy. The EoM is $$ i \partial_t \rho_E = \left[ \frac{\delta m^2}{2E}B ,\rho_E \right] $$

while the EoM for antineutrinos is $$ i \partial_t \bar\rho_E = \left[- \frac{\delta m^2}{2E}B ,\bar\rho_E \right] $$

Initial: Homogeneous, Isotropic, Monoenergetic $\nu_e$ and $\bar\nu_e$

The equations becomes $$ i \partial_t \rho_E = \left[ \frac{\delta m^2}{2E} B ,\rho_E \right] $$ $$ i \partial_t \bar\rho_E = \left[- \frac{\delta m^2}{2E}B,\bar\rho_E \right] $$

Define $\omega=\frac{\delta m^2}{2E}$, $\omega = \frac{\delta m^2}{-2E}$, $\mu=\sqrt{2}G_F n_\nu$ $$ i \partial_t \rho_E = \left[ \omega B ,\rho_E \right] $$ $$ i \partial_t \bar\rho_E = \left[\bar\omega B,\bar\rho_E \right] $$

where

$$ B = \frac{1}{2} \begin{pmatrix} -\cos 2\theta_v & \sin 2\theta_v \\ \sin 2\theta_v & \cos 2\theta_v \end{pmatrix} $$

or just use theta =0.2rad

$$ L = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} $$

Initial condition $$ \rho(t=0) = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} $$

$$ \bar\rho(t=0) =\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} $$

define the following quantities

  1. hbar$=\hbar$ %2. delm2E$= \delta m^2/2E$ %3. lamb $= \lambda$, lambb $= \bar\lambda$ %4. gF $= G_F$ %5. mu $=\mu$
  2. omega $=\omega$, omegab $=-\bar\omega$

Numerical


In [1]:
# This line configures matplotlib to show figures embedded in the notebook, 
# instead of opening a new window for each figure. More about that later. 
# If you are using an old version of IPython, try using '%pylab inline' instead.
%matplotlib inline
%load_ext snakeviz

import numpy as np
from scipy.optimize import minimize
from scipy.special import expit
import matplotlib.pyplot as plt

from matplotlib.lines import Line2D

import timeit

import pandas as pd

import plotly.plotly as py
from plotly.graph_objs import *
import plotly.tools as tls

In [92]:
# hbar=1.054571726*10**(-34)
hbar=1.0
delm2E=1.0
# lamb=1.0  ## lambda for neutrinos
# lambb=1.0 ## lambda for anti neutrinos
# gF=1.0
# nd=1.0  ## number density
# ndb=1.0   ## number density
omega=1.0
omegab=-1.0

## Here are some matrices to be used

elM = np.array([[1.0,0.0],[0.0,0.0]])
#bM = 1.0/2*np.array( [ [ - 0.38729833462,0.31622776601] , [0.31622776601,0.38729833462] ] )
bM = 1.0/2*np.array( [ [ -np.cos(0.4),np.sin(0.4)] , [np.sin(0.4),np.cos(0.4)] ] )

print bM
## sqareroot of 2
sqrt2=np.sqrt(2.0)


[[-0.4605305   0.19470917]
 [ 0.19470917  0.4605305 ]]

I am going to substitute all density matrix elements using their corrosponding network expressions.

So first of all, I need the network expression for the unknown functions.

A function is written as

$$ y_i= initial+t_i v_k f(t_i w_k+u_k) ,$$

while it's derivative is

$$v_k f(t w_k+u_k) + t v_k f(tw_k+u_k) (1-f(tw_k+u_k)) w_k .$$

Now I can write down the equations using these two forms.


In [93]:
def trigf(x):
    #return 1/(1+np.exp(-x)) # It's not bad to define this function here for people could use other functions other than expit(x).
    return expit(x)

In [94]:
## The time derivative part

### Here are the initial conditions

init = np.array( [[1,0],[0,0]] )
#init = np.array( [[1,2],[3,4]] )

### For neutrinos

def rho(x,ti,initialCondition): # x is the input structure arrays, ti is a time point
    
    elem=np.ones(4)
    
    for i in np.linspace(0,3,4):
        elem[i] = np.sum(ti * x[i*3] * trigf( ti*x[i*3+1] + x[i*3+2] ) )
    
    return initialCondition + np.array([[ elem[0] , elem[1] ],[elem[2], elem[3] ]])

In [95]:
## Test
xtemp=np.ones(120)
rho(xtemp,0,init)


Out[95]:
array([[ 1.,  0.],
       [ 0.,  0.]])

In [96]:
## Define Hamiltonians for both

def hamilv():
    return delm2E*bM

In [97]:
## The commutator

def commv(x,ti,initialCondition):
    
    return np.dot(hamilv(), rho(x,ti,initialCondition) ) - np.dot(rho(x,ti,initialCondition), hamilv() )

In [98]:
## Test

print bM

print hamilv()

print "neutrino\n",commv(xtemp,0,init)


[[-0.4605305   0.19470917]
 [ 0.19470917  0.4605305 ]]
[[-0.4605305   0.19470917]
 [ 0.19470917  0.4605305 ]]
neutrino
[[ 0.         -0.19470917]
 [ 0.19470917  0.        ]]

A function is written as

$$ y_i= initial+t_i v_k f(t_i w_k+u_k) ,$$

while it's derivative is

$$v_k f(t w_k+u_k) + t v_k f(tw_k+u_k) (1-f(tw_k+u_k)) w_k .$$

In [124]:
## The COST of the eqn set

regularization = 0.0001
npsum = np.sum

def costvTi(x,ti,initialCondition): # l is total length of x
    
    list = np.linspace(0,3,4)

    fvec = []
    costi = np.ones(4) + 1.0j* np.ones(4)
    commvi = np.array([commv(x,ti,initialCondition)[0,0],commv(x,ti,initialCondition)[0,1],commv(x,ti,initialCondition)[1,0],commv(x,ti,initialCondition)[1,1] ])
    
    fvecappend = fvec.append
    
    for i in list:
        fvecappend(np.asarray(trigf(ti*1.0*x[i*3+1] + 1.0*x[i*3+2]) ) )
        
    fvec = np.array(fvec)
    
    for i in list:
        costi[i] = ( np.sum (1.0*x[i*3]*fvec[i] + 1.0*ti * x[i*3]* fvec[i] * ( 1.0 -  fvec[i]  ) * x[i*3+1] ) + 1.0j*  ( commvi[i] )  )  

    costiTemp = 0.0
    
    for i in list:
        costiTemp = costiTemp + (np.real(costi[i]))**2 + (np.imag(costi[i]))**2

    
    return costiTemp
    
    #return np.abs(np.real(costi11)) + np.abs(np.real(costi12))+ np.abs(np.real(costi21)) +  np.abs(np.real(costi22)) + np.abs(np.imag(costi11)) + np.abs(np.imag(costi12))+ np.abs(np.imag(costi21)) +  np.abs(np.imag(costi22))

    #return ( (np.real(costi11))**2 + (np.real(costi12))**2+ (np.real(costi21))**2 +  (np.real(costi22))**2 + (np.imag(costi11))**2 + (np.imag(costi12))**2+ (np.imag(costi21))**2 +  (np.imag(costi22))**2 )/v11.size + regularization * ( np.sum(v11**2)+np.sum(v12**2)+np.sum(v21**2) + np.sum(v22**2) + np.sum(w11**2) + np.sum(w12**2)+ np.sum(w21**2)+ np.sum(w22**2) )



def CostOfStructure(x):
    
    v11,w11,u11,v12,w12,u12,v21,w21,u21,v22,w22,u22 = x[:12]
    
    return regularization * ( np.sum(v11**2)+np.sum(v12**2)+np.sum(v21**2) + np.sum(v22**2) + np.sum(w11**2) + np.sum(w12**2)+ np.sum(w21**2)+ np.sum(w22**2) )

In [125]:
print costvTi(xtemp,2,init), costvTi2(xtemp,2,init)


11.9516331412 11.9516331412

In [102]:
## Calculate the total cost

def costv(x,t,initialCondition):

    t = np.array(t)
    
    costvTotal = np.sum( costvTList(x,t,initialCondition)  )
        
    return costvTotal
    

def costvTList(x,t,initialCondition):  ## This is the function WITHOUT the square!!! 
        
    t = np.array(t)
    
    costvList = np.asarray([])
    
    for temp in t:
        tempElement = costvTi(x,temp,initialCondition)
        costvList = np.append(costvList, tempElement)
        
    return np.array(costvList)

In [103]:
ttemp = np.linspace(0,10)
print ttemp


[  0.           0.20408163   0.40816327   0.6122449    0.81632653
   1.02040816   1.2244898    1.42857143   1.63265306   1.83673469
   2.04081633   2.24489796   2.44897959   2.65306122   2.85714286
   3.06122449   3.26530612   3.46938776   3.67346939   3.87755102
   4.08163265   4.28571429   4.48979592   4.69387755   4.89795918
   5.10204082   5.30612245   5.51020408   5.71428571   5.91836735
   6.12244898   6.32653061   6.53061224   6.73469388   6.93877551
   7.14285714   7.34693878   7.55102041   7.75510204   7.95918367
   8.16326531   8.36734694   8.57142857   8.7755102    8.97959184
   9.18367347   9.3877551    9.59183673   9.79591837  10.        ]

In [104]:
ttemp = np.linspace(0,10)
print costvTList(xtemp,ttemp,init)
print costv(xtemp,ttemp,init)


[   2.2136099     2.82542057    3.50674411    4.25935949    5.08963359
    6.00708951    7.02267217    8.14722876    9.39045557   10.76034338
   12.26302826   13.90291194   15.68292596   17.6048451    19.66959072
   21.87749312   24.22850159   26.72234275   29.35863356   32.13695768
   35.05691384   38.11814371   41.32034556   44.66327835   48.14675997
   51.77066195   55.5349025    59.43943894   63.48426033   67.66938059
   71.99483247   76.46066233   81.06692578   85.81368417   90.70100169
   95.72894325  100.89757274  106.20695188  111.65713932  117.2481901
  122.98015532  128.85308201  134.8670131   141.02198754  147.31804043
  153.75520324  160.33350408  167.05296793  173.91361689  180.91547049]
3226.66081823

Jacobian

def commvprimew(x,ti,initialCondition): # this is the prime of commutator with respect to w.

return cprimew

def costvJaci(x,ti,initialCondition):

v11,w11,u11,v12,w12,u12,v21,w21,u21,v22,w22,u22 = x[:12]

out = np.zeros(12)

fvec11 = np.array(trigf(ti*w11 + u11) )  # This is a vector!!!
fvec12 = np.array(trigf(ti*w12 + u12) )
fvec21 = np.array(trigf(ti*w21 + u21) )
fvec22 = np.array(trigf(ti*w22 + u22) )

fvec11w = np.array( ti*fvec11 * ( 1- fvec11 ) * w11 )  # This is a vector!!!
fvec12w = np.array( ti*fvec12 * ( 1- fvec12 ) * w12 ) 
fvec21w = np.array( ti*fvec21 * ( 1- fvec21 ) * w21 ) 
fvec22w = np.array( ti*fvec22 * ( 1- fvec22 ) * w22 ) 

fvec11u = np.array( fvec11 * ( 1- fvec11 ) * u11 )  # This is a vector!!!
fvec12u = np.array( fvec12 * ( 1- fvec12 ) * u12 ) 
fvec21u = np.array( fvec21 * ( 1- fvec21 ) * u21 ) 
fvec22u = np.array( fvec22 * ( 1- fvec22 ) * u22 ) 

rt11= initialCondition[0,0] + np.sum(ti * v11 * fvec11 )
rt12= initialCondition[0,1] + np.sum(ti * v12 * fvec12 )
rt21= initialCondition[1,0] + np.sum(ti * v21 * fvec21 )
rt22= initialCondition[1,1] + np.sum(ti * v22 * fvec22 )

costi11= ( np.sum (v11*fvec11 + ti * v11* fvec11 * ( 1 -  fvec11  ) * w11 ) + 1.0j*  ( commv(x,ti,initialCondition)[0,0] )  )  
costi12= ( np.sum (v12*fvec12 + ti * v12* fvec12 * ( 1 -  fvec12  ) * w12 ) + 1.0j*  ( commv(x,ti,initialCondition)[0,1] )  )  
costi21= ( np.sum (v21*fvec21 + ti * v21* fvec21 * ( 1 -  fvec21  ) * w21 ) + 1.0j*  ( commv(x,ti,initialCondition)[1,0] )  )  
costi22= ( np.sum (v22*fvec22 + ti * v22* fvec22 * ( 1 -  fvec22  ) * w22 ) + 1.0j*  ( commv(x,ti,initialCondition)[1,1] )  )  

funprime11w = np.sum (v11*fvec11w + ti * v11* fvec11w * ( 1 -  fvec11  ) * w11 + ti * v11* fvec11 * ( 1 -  fvec11  ) - ti * v11 * fvec11 * fvec11w * w11 )
funprime12w = np.sum (v12*fvec12w + ti * v12* fvec12w * ( 1 -  fvec12  ) * w12 + ti * v12* fvec12 * ( 1 -  fvec12  ) - ti * v12 * fvec12 * fvec12w * w12 )
funprime21w = np.sum (v21*fvec21w + ti * v21* fvec21w * ( 1 -  fvec21  ) * w21 + ti * v21* fvec21 * ( 1 -  fvec21  ) - ti * v21 * fvec21 * fvec21w * w21 )
funprime22w = np.sum (v22*fvec22w + ti * v22* fvec22w * ( 1 -  fvec22  ) * w22 + ti * v22* fvec22 * ( 1 -  fvec22  ) - ti * v22 * fvec22 * fvec22w * w22 )

commvprime11w = commv(x,ti,initialCondition)[0,1]

#costi11pw = ( funprime11w + 1.0j *  ( commvprimew(x,ti,initialCondition)[0,0]   )  )
#costi12pw = ( funprime12w + 1.0j *  (  commvprimew(x,ti,initialCondition)[0,1]  )  )  
#costi21pw = ( funprime21w + 1.0j *  ( commvprimew(x,ti,initialCondition)[1,0] )  )  
#costi22pw = ( funprime22w + 1.0j *  ( commvprimew(x,ti,initialCondition)[1,1] )  )  

costi11pw = ( funprime11w + 1.0j *  ( commvprimew(x,ti,initialCondition)[0,0]   )  )
costi12pw = ( funprime12w + 1.0j *  (  commvprimew(x,ti,initialCondition)[0,1]  )  )  
costi21pw = ( funprime21w + 1.0j *  ( commvprimew(x,ti,initialCondition)[1,0] )  )  
costi22pw = ( funprime22w + 1.0j *  ( commvprimew(x,ti,initialCondition)[1,1] )  )  


return np.array(out)

def costvJac(v,w,u,t): v = np.array(v) w = np.array(w) u = np.array(u)

vout = 0
wout = 0
uout = 0

for temp in t:
    vout = vout + 2*mhelper(v,w,u,temp)*vhelper(v,w,u,temp)
    wout = wout + 2*mhelper(v,w,u,temp)*whelper(v,w,u,temp)
    uout = uout + 2*mhelper(v,w,u,temp)*uhelper(v,w,u,temp)

out = np.hstack((vout,wout,uout))

return np.array(out)

In [ ]:

Minimization

Here is the minimization


In [105]:
tlin = np.linspace(0,10,10)
# tlinTest = np.linspace(0,14,10) + 0.5
# initGuess = np.ones(120)
# initGuess = np.asarray(np.split(np.random.rand(1,720)[0],12))
initGuess = np.asarray(np.split(np.random.rand(1,60)[0],12))
    


costvF = lambda x: costv(x,tlin,init)
#costvFTest = lambda x: costv(x,tlinTest,init)

In [106]:
print costv(initGuess,tlin,init)#, costv(initGuess,tlinTest,init)


1487.99577436

In [107]:
## %%snakeviz
# startCG = timeit.default_timer()
#costvFResultCG = minimize(costvF,initGuess,method="CG")
#stopCG = timeit.default_timer()

#print stopCG - startCG

#print costvFResultCG

%%snakeviz startNM = timeit.default_timer() costvFResultNM = minimize(costvF,initGuess,method="Nelder-Mead",options={"maxfun":20000}) stopNM = timeit.default_timer()

print stopNM - startNM

print costvFResultNM

initGuessIter = costvFResultNM.get("x")

for TOLERANCE in np.asarray([1e-8,1e-9,1e-12,1e-14,1e-16,1e-19,1e-20,1e-21,1e-22]): costvFResultNMIter = minimize(costvF,initGuessIter,method="Nelder-Mead",tol=TOLERANCE,options={"maxfun":90000,"maxiter":900000}) initGuessIter = costvFResultNMIter.get("x") print TOLERANCE,costvFResultNMIter


In [108]:
#%%snakeviz
#startBFGS = timeit.default_timer()
#costvFResultBFGS = minimize(costvF,initGuess,method="BFGS")
#stopBFGS = timeit.default_timer()

#print stopBFGS - startBFGS

#print costvFResultBFGS

initGuessIter = initGuess

for TOLERANCE in np.asarray([1e-19,1e-20,1e-21,1e-22]): costvFResultSLSQP = minimize(costvF,initGuessIter,method="SLSQP",tol=TOLERANCE) initGuessIter = costvFResultSLSQP.get("x") print TOLERANCE,costvFResultSLSQP


In [109]:
%%snakeviz
startSLSQP = timeit.default_timer()
costvFResultSLSQP = minimize(costvF,initGuess,method="SLSQP",tol=1e-10)
stopSLSQP = timeit.default_timer()

print stopSLSQP - startSLSQP

print costvFResultSLSQP


59.4442219734
  status: 0
 success: True
    njev: 51
    nfev: 3174
     fun: 0.28917217200293521
       x: array([ -5.44851228e-02,   2.79892128e+01,  -1.24370743e+01,
        -6.23813582e-03,   2.08247473e+01,   1.23003675e+01,
         3.10448806e+00,  -3.36350119e+00,  -1.75085282e+01,
         5.44850653e-02,   2.72891168e+01,  -1.10588144e+01,
         2.06842411e-01,   3.71516793e-01,   4.42953041e-01,
         4.09312972e-01,   4.69538390e-01,   4.85402206e-01,
         2.81039273e-01,   6.77679697e-01,   2.52299185e-01,
         2.67446298e-03,   4.57328005e-01,   2.84634334e-01,
         1.37886240e-02,   1.73553559e-01,   3.53048530e-01,
         7.45781077e-01,   8.14907193e-01,   3.15614028e-01,
         6.32704308e-02,   3.92412308e-01,   6.47945672e-01,
         3.10839879e-01,   1.04914155e-01,   1.46859914e-01,
         4.49436714e-01,   8.58022257e-01,   6.77305399e-01,
         9.32723047e-02,   7.67227509e-01,   3.88149880e-01,
         6.14422293e-01,   2.92083554e-01,   4.41417286e-01,
         1.20828517e-01,   7.39381855e-01,   6.41867842e-01,
         6.02782521e-01,   9.48355576e-01,   2.74875353e-01,
         8.51261167e-01,   3.67914102e-01,   5.98250618e-01,
         9.13689197e-01,   3.01212466e-01,   2.71666043e-01,
         1.80152269e-01,   3.02400165e-01,   5.49523109e-02])
 message: 'Optimization terminated successfully.'
     jac: array([ -7.63684511e-07,   0.00000000e+00,   0.00000000e+00,
        -1.03898346e-05,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         7.86036253e-07,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00])
     nit: 51
 
*** Profile stats marshalled to file u'/var/folders/mj/1sl30v6x2g5_lnlgdnngtd3c0000gn/T/tmpfLqFNY'. 

In [110]:
#%%snakeviz
#startSLSQPTest = timeit.default_timer()
#costvFResultSLSQPTest = minimize(costvFTest,initGuess,method="SLSQP")
#stopSLSQPTest = timeit.default_timer()

#print stopSLSQPTest - startSLSQPTest

#print costvFResultSLSQPTest

In [111]:
print costvFResultSLSQP.get('x')
print np.asarray(np.split(costvFResultSLSQP.get('x'),12))
print CostOfStructure(np.asarray(np.split(costvFResultSLSQP.get('x'),12)))


[ -5.44851228e-02   2.79892128e+01  -1.24370743e+01  -6.23813582e-03
   2.08247473e+01   1.23003675e+01   3.10448806e+00  -3.36350119e+00
  -1.75085282e+01   5.44850653e-02   2.72891168e+01  -1.10588144e+01
   2.06842411e-01   3.71516793e-01   4.42953041e-01   4.09312972e-01
   4.69538390e-01   4.85402206e-01   2.81039273e-01   6.77679697e-01
   2.52299185e-01   2.67446298e-03   4.57328005e-01   2.84634334e-01
   1.37886240e-02   1.73553559e-01   3.53048530e-01   7.45781077e-01
   8.14907193e-01   3.15614028e-01   6.32704308e-02   3.92412308e-01
   6.47945672e-01   3.10839879e-01   1.04914155e-01   1.46859914e-01
   4.49436714e-01   8.58022257e-01   6.77305399e-01   9.32723047e-02
   7.67227509e-01   3.88149880e-01   6.14422293e-01   2.92083554e-01
   4.41417286e-01   1.20828517e-01   7.39381855e-01   6.41867842e-01
   6.02782521e-01   9.48355576e-01   2.74875353e-01   8.51261167e-01
   3.67914102e-01   5.98250618e-01   9.13689197e-01   3.01212466e-01
   2.71666043e-01   1.80152269e-01   3.02400165e-01   5.49523109e-02]
[[ -5.44851228e-02   2.79892128e+01  -1.24370743e+01  -6.23813582e-03
    2.08247473e+01]
 [  1.23003675e+01   3.10448806e+00  -3.36350119e+00  -1.75085282e+01
    5.44850653e-02]
 [  2.72891168e+01  -1.10588144e+01   2.06842411e-01   3.71516793e-01
    4.42953041e-01]
 [  4.09312972e-01   4.69538390e-01   4.85402206e-01   2.81039273e-01
    6.77679697e-01]
 [  2.52299185e-01   2.67446298e-03   4.57328005e-01   2.84634334e-01
    1.37886240e-02]
 [  1.73553559e-01   3.53048530e-01   7.45781077e-01   8.14907193e-01
    3.15614028e-01]
 [  6.32704308e-02   3.92412308e-01   6.47945672e-01   3.10839879e-01
    1.04914155e-01]
 [  1.46859914e-01   4.49436714e-01   8.58022257e-01   6.77305399e-01
    9.32723047e-02]
 [  7.67227509e-01   3.88149880e-01   6.14422293e-01   2.92083554e-01
    4.41417286e-01]
 [  1.20828517e-01   7.39381855e-01   6.41867842e-01   6.02782521e-01
    9.48355576e-01]
 [  2.74875353e-01   8.51261167e-01   3.67914102e-01   5.98250618e-01
    9.13689197e-01]
 [  3.01212466e-01   2.71666043e-01   1.80152269e-01   3.02400165e-01
    5.49523109e-02]]
0.18585443372

In [112]:
#np.savetxt('./assets/homogen/optimize_ResultSLSQPT2120_Vac.txt', costvFResultSLSQP.get('x'), delimiter = ',')

Functions

Find the solutions to each elements.


In [113]:
# costvFResultSLSQPx = np.genfromtxt('./assets/homogen/optimize_ResultSLSQP.txt', delimiter = ',')

In [114]:
## The first element of neutrino density matrix
xresult = np.asarray(costvFResultSLSQP.get('x'))
#xresult = np.asarray(costvFResultNM.get('x'))
#xresult = np.asarray(costvFResultBFGS.get('x'))

print xresult

plttlin=np.linspace(0,10,100)

pltdata11 = np.array([])
pltdata11Test = np.array([])
pltdata22 = np.array([])
pltdata12 = np.array([])
pltdata21 = np.array([])

for i in plttlin:
    pltdata11 = np.append(pltdata11 ,rho(xresult,i,init)[0,0] )
    
print pltdata11

for i in plttlin:
    pltdata12 = np.append(pltdata12 ,rho(xresult,i,init)[0,1] )
    
print pltdata12

for i in plttlin:
    pltdata21 = np.append(pltdata21 ,rho(xresult,i,init)[1,0] )
    
print pltdata21

#for i in plttlin:
#    pltdata11Test = np.append(pltdata11Test ,rho(xresultTest,i,init)[0,0] )
#    
#print pltdata11Test


for i in plttlin:
    pltdata22 = np.append(pltdata22 ,rho(xresult,i,init)[1,1] )
    
print pltdata22

print rho(xresult,0,init)


[ -5.44851228e-02   2.79892128e+01  -1.24370743e+01  -6.23813582e-03
   2.08247473e+01   1.23003675e+01   3.10448806e+00  -3.36350119e+00
  -1.75085282e+01   5.44850653e-02   2.72891168e+01  -1.10588144e+01
   2.06842411e-01   3.71516793e-01   4.42953041e-01   4.09312972e-01
   4.69538390e-01   4.85402206e-01   2.81039273e-01   6.77679697e-01
   2.52299185e-01   2.67446298e-03   4.57328005e-01   2.84634334e-01
   1.37886240e-02   1.73553559e-01   3.53048530e-01   7.45781077e-01
   8.14907193e-01   3.15614028e-01   6.32704308e-02   3.92412308e-01
   6.47945672e-01   3.10839879e-01   1.04914155e-01   1.46859914e-01
   4.49436714e-01   8.58022257e-01   6.77305399e-01   9.32723047e-02
   7.67227509e-01   3.88149880e-01   6.14422293e-01   2.92083554e-01
   4.41417286e-01   1.20828517e-01   7.39381855e-01   6.41867842e-01
   6.02782521e-01   9.48355576e-01   2.74875353e-01   8.51261167e-01
   3.67914102e-01   5.98250618e-01   9.13689197e-01   3.01212466e-01
   2.71666043e-01   1.80152269e-01   3.02400165e-01   5.49523109e-02]
[ 1.          0.99999963  0.99998754  0.99968978  0.99461809  0.97673678
  0.96733228  0.96149982  0.95597329  0.95046818  0.94496453  0.93946098
  0.93395743  0.92845388  0.92295033  0.91744678  0.91194324  0.90643969
  0.90093614  0.89543259  0.88992904  0.8844255   0.87892195  0.8734184
  0.86791485  0.86241131  0.85690776  0.85140421  0.84590066  0.84039712
  0.83489357  0.82939002  0.82388647  0.81838292  0.81287938  0.80737583
  0.80187228  0.79636873  0.79086519  0.78536164  0.77985809  0.77435454
  0.76885099  0.76334745  0.7578439   0.75234035  0.7468368   0.74133326
  0.73582971  0.73032616  0.72482261  0.71931906  0.71381552  0.70831197
  0.70280842  0.69730487  0.69180133  0.68629778  0.68079423  0.67529068
  0.66978713  0.66428359  0.65878004  0.65327649  0.64777294  0.6422694
  0.63676585  0.6312623   0.62575875  0.6202552   0.61475166  0.60924811
  0.60374456  0.59824101  0.59273747  0.58723392  0.58173037  0.57622682
  0.57072327  0.56521973  0.55971618  0.55421263  0.54870908  0.54320554
  0.53770199  0.53219844  0.52669489  0.52119135  0.5156878   0.51018425
  0.5046807   0.49917715  0.49367361  0.48817006  0.48266651  0.47716296
  0.47165942  0.46615587  0.46065232  0.45514877]
[ 0.         -0.00063011 -0.00126023 -0.00189034 -0.00252046 -0.00315057
 -0.00378069 -0.0044108  -0.00504092 -0.00567103 -0.00630115 -0.00693126
 -0.00756138 -0.00819149 -0.00882161 -0.00945172 -0.01008184 -0.01071195
 -0.01134207 -0.01197218 -0.01260229 -0.01323241 -0.01386252 -0.01449264
 -0.01512275 -0.01575287 -0.01638298 -0.0170131  -0.01764321 -0.01827333
 -0.01890344 -0.01953356 -0.02016367 -0.02079379 -0.0214239  -0.02205402
 -0.02268413 -0.02331424 -0.02394436 -0.02457447 -0.02520459 -0.0258347
 -0.02646482 -0.02709493 -0.02772505 -0.02835516 -0.02898528 -0.02961539
 -0.03024551 -0.03087562 -0.03150574 -0.03213585 -0.03276597 -0.03339608
 -0.0340262  -0.03465631 -0.03528642 -0.03591654 -0.03654665 -0.03717677
 -0.03780688 -0.038437   -0.03906711 -0.03969723 -0.04032734 -0.04095746
 -0.04158757 -0.04221769 -0.0428478  -0.04347792 -0.04410803 -0.04473815
 -0.04536826 -0.04599838 -0.04662849 -0.0472586  -0.04788872 -0.04851883
 -0.04914895 -0.04977906 -0.05040918 -0.05103929 -0.05166941 -0.05229952
 -0.05292964 -0.05355975 -0.05418987 -0.05481998 -0.0554501  -0.05608021
 -0.05671033 -0.05734044 -0.05797056 -0.05860067 -0.05923078 -0.0598609
 -0.06049101 -0.06112113 -0.06175124 -0.06238136]
[  0.00000000e+00   5.55836578e-09   7.91455708e-09   8.45215339e-09
   8.02334749e-09   7.14027782e-09   6.10022496e-09   5.06689769e-09
   4.12271750e-09   3.30206481e-09   2.61211671e-09   2.04566614e-09
   1.58881310e-09   1.22541845e-09   9.39547174e-10   7.16689940e-10
   5.44263896e-10   4.11706723e-10   3.10356637e-10   2.33233874e-10
   1.74790376e-10   1.30664108e-10   9.74561362e-11   7.25377096e-11
   5.38885798e-11   3.99645566e-11   2.95908767e-11   2.18775026e-11
   1.61525653e-11   1.19105267e-11   8.77210287e-12   6.45347526e-12
   4.74276305e-12   3.48212922e-12   2.55422620e-12   1.87196609e-12
   1.37082472e-12   1.00306862e-12   7.33435642e-13   5.35910808e-13
   3.91324820e-13   2.85568798e-13   2.08269504e-13   1.51807889e-13
   1.10593106e-13   8.05262338e-14   5.86046666e-14   4.26306270e-14
   3.09966382e-14   2.25278077e-14   1.63659925e-14   1.18848038e-14
   8.62729556e-15   6.26032236e-15   4.54113153e-15   3.29293005e-15
   2.38702703e-15   1.72979110e-15   1.25313047e-15   9.07548417e-16
   6.57080436e-16   4.75605223e-16   3.44158075e-16   2.48975331e-16
   1.80071605e-16   1.30205135e-16   9.41256930e-17   6.80281323e-17
   4.91555039e-17   3.55109118e-17   2.56483994e-17   1.85212405e-17
   1.33719182e-17   9.65236131e-18   6.96613560e-18   5.02656105e-18
   3.62637561e-18   2.61576914e-18   1.88648251e-18   1.36030021e-18
   9.80724797e-19   7.06954856e-19   5.09530294e-19   3.67183996e-19
   2.64566244e-19   1.90600294e-19   1.37294325e-19   9.88832839e-20
   7.12091488e-20   5.12734598e-20   3.69142985e-20   2.65731474e-20
   1.91266507e-20   1.37652322e-20   9.90553509e-21   7.12726960e-21
   5.12767285e-21   3.68867425e-21   2.65322536e-21   1.90823893e-21]
[  0.00000000e+00   1.36419057e-06   4.27999450e-05   9.55973295e-04
   1.08259861e-02   2.58227037e-02   3.28841529e-02   3.85145948e-02
   4.40275951e-02   4.95318246e-02   5.50354157e-02   6.05389611e-02
   6.60425033e-02   7.15460453e-02   7.70495872e-02   8.25531292e-02
   8.80566711e-02   9.35602131e-02   9.90637550e-02   1.04567297e-01
   1.10070839e-01   1.15574381e-01   1.21077923e-01   1.26581465e-01
   1.32085007e-01   1.37588549e-01   1.43092091e-01   1.48595633e-01
   1.54099174e-01   1.59602716e-01   1.65106258e-01   1.70609800e-01
   1.76113342e-01   1.81616884e-01   1.87120426e-01   1.92623968e-01
   1.98127510e-01   2.03631052e-01   2.09134594e-01   2.14638136e-01
   2.20141678e-01   2.25645220e-01   2.31148762e-01   2.36652304e-01
   2.42155846e-01   2.47659388e-01   2.53162930e-01   2.58666471e-01
   2.64170013e-01   2.69673555e-01   2.75177097e-01   2.80680639e-01
   2.86184181e-01   2.91687723e-01   2.97191265e-01   3.02694807e-01
   3.08198349e-01   3.13701891e-01   3.19205433e-01   3.24708975e-01
   3.30212517e-01   3.35716059e-01   3.41219601e-01   3.46723143e-01
   3.52226685e-01   3.57730226e-01   3.63233768e-01   3.68737310e-01
   3.74240852e-01   3.79744394e-01   3.85247936e-01   3.90751478e-01
   3.96255020e-01   4.01758562e-01   4.07262104e-01   4.12765646e-01
   4.18269188e-01   4.23772730e-01   4.29276272e-01   4.34779814e-01
   4.40283356e-01   4.45786898e-01   4.51290440e-01   4.56793982e-01
   4.62297523e-01   4.67801065e-01   4.73304607e-01   4.78808149e-01
   4.84311691e-01   4.89815233e-01   4.95318775e-01   5.00822317e-01
   5.06325859e-01   5.11829401e-01   5.17332943e-01   5.22836485e-01
   5.28340027e-01   5.33843569e-01   5.39347111e-01   5.44850653e-01]
[[ 1.  0.]
 [ 0.  0.]]

In [115]:
rho(xresult,1,init)


Out[115]:
array([[  9.45514887e-01,  -6.23813582e-03],
       [  2.67536366e-09,   5.44850604e-02]])

In [116]:
#np.savetxt('./assets/homogen/optimize_pltdatar11.txt', pltdata11, delimiter = ',')
#np.savetxt('./assets/homogen/optimize_pltdatar22.txt', pltdata22, delimiter = ',')

In [117]:
plt.figure(figsize=(16,9.36))
plt.ylabel('rho11')
plt.xlabel('Time')
plt11=plt.plot(plttlin,pltdata11,"b4-",label="vac_rho11")
#plt.plot(plttlin,pltdata11Test,"m4-",label="vac_rho11Test")
plt.show()
#py.iplot_mpl(plt.gcf(),filename="vac_HG-rho11")


# tls.embed("https://plot.ly/~emptymalei/73/")



In [118]:
plt.figure(figsize=(16,9.36))
plt.ylabel('rho12')
plt.xlabel('Time')
plt12=plt.plot(plttlin,pltdata12,"b4-",label="vac_rho12")
#plt.plot(plttlin,pltdata11Test,"m4-",label="vac_rho11Test")
plt.show()
#py.iplot_mpl(plt.gcf(),filename="vac_HG-rho11")


# tls.embed("https://plot.ly/~emptymalei/73/")



In [119]:
plt.figure(figsize=(16,9.36))
plt.ylabel('rho21')
plt.xlabel('Time')
plt11=plt.plot(plttlin,pltdata21,"b4-",label="vac_rho21")
#plt.plot(plttlin,pltdata11Test,"m4-",label="vac_rho11Test")
plt.show()
#py.iplot_mpl(plt.gcf(),filename="vac_HG-rho11")


# tls.embed("https://plot.ly/~emptymalei/73/")



In [120]:
plt.figure(figsize=(16,9.36))
plt.ylabel('Time')
plt.xlabel('rho22')
plt22=plt.plot(plttlin,pltdata22,"r4-",label="vac_rho22")
plt.show()
#py.iplot_mpl(plt.gcf(),filename="vac_HG-rho22")



In [121]:
MMA_optmize_Vac_pltdata = np.genfromtxt('./assets/homogen/MMA_optmize_Vac_pltdata.txt', delimiter = ',')

plt.figure(figsize=(16,9.36))
plt.ylabel('MMArho11')
plt.xlabel('Time')
plt.plot(np.linspace(0,15,4501),MMA_optmize_Vac_pltdata,"r-",label="MMAVacrho11")
plt.plot(plttlin,pltdata11,"b4-",label="vac_rho11")
plt.show()
#py.iplot_mpl(plt.gcf(),filename="MMA-rho11-Vac-80-60")



In [ ]:


In [ ]:

Practice


In [ ]:
xtemp1 = np.arange(4)
xtemp1.shape = (2,2)
print xtemp1
xtemp1[0,1]
np.dot(xtemp1,xtemp1)
xtemp1[0,1]

In [ ]:


In [ ]: