Exemplo n.º 1
0
def getMCMCchainForSamplesSize( iSampleSize, nIterations,\
                    hubbleInterpolaterClass):
    samples = None


    pklFile = 'picklesDualMass/multiFitSamples_dualMass_%i.pkl' \
          % (iSampleSize)

    if os.path.isfile(pklFile):
        return pkl.load(open(pklFile, 'rb'))

    logProb = np.array([])
    for iIteration in range(nIterations):
        print("Iteration: %i/%i" % (iIteration + 1, nIterations))
        selectedTimeDelays = \
              selectRandomSampleOfTimeDelays( iSampleSize)

        fitHubbleClass = \
              fitHubble.fitHubbleParameterClass( selectedTimeDelays, \
                                    hubbleInterpolaterClass)

        y, x = np.histogram(fitHubbleClass.samples[:, 0])
        xc = (x[1:] + x[:-1]) / 2.

        if samples is None:
            samples = fitHubbleClass.samples
        else:
            samples = np.vstack((samples, fitHubbleClass.samples))

        pdb.set_trace()
    pkl.dump(samples, open(pklFile, 'wb'))

    return samples
Exemplo n.º 2
0
def main(pklFile='fitDataToModel_withMass_LCDMk_noZ0.6.pkl', \
             monteCarlo=False):

    if not os.path.isfile('pickles/monteCarlosOfData/%s' % pklFile):

        selectedTimeDelays = getObservations(monteCarlo=monteCarlo)

        dataSelectionFunction = '../output/CDM/selectionFunction/SF_data.pkl'

        hubbleInterpolaterClass = \
          hubbleInterpolator(allDistributionsPklFile=dataSelectionFunction)

        hubbleInterpolaterClass.getTrainingData(
            'pickles/trainingDataForObsWithMass.pkl')

        hubbleInterpolaterClass.getTimeDelayModel()



        fitHubbleClass = \
          fitHubble.fitHubbleParameterClass( selectedTimeDelays, \
                                    hubbleInterpolaterClass)

        pkl.dump(fitHubbleClass.samples,
                 open('pickles/monteCarlosOfData/%s' % pklFile, 'wb'))
        samples = fitHubbleClass.samples
    else:

        samples = pkl.load(open('pickles/monteCarlosOfData/%s' % pklFile,
                                'rb'))

    if monteCarlo:
        return samples

    ndim = samples.shape[1]
    figcorner, axarr = plt.subplots(ndim, ndim, figsize=(8, 8))

    parRange = [[0.55, 0.8], [0.45, 0.6], [-2., -1.6]]
    labels = \
      [r'$H_0/ (100 $km s$^{-1}$Mpc$^{-1}$)',r'$z_{lens}$',r'$\alpha$', r'$log(M(<5kpc)/M_\odot)$'\
           r'$\Omega_M$',r'$\Omega_\Lambda$',r'$\Omega_K$', r'$Sigma' ]
    nsamples = samples.shape[0]
    #plotMockedData( figcorner)

    corner.corner(samples,  levels=[0.68], bins=20,\
                    plot_datapoints=False, labels=labels, fig=figcorner,\
                      weights=np.ones(nsamples)/nsamples, color='black', \
                      hist_kwargs={'linewidth':3.},\
                      contour_kwargs={'linewidths':3.}, smooth=True)

    for i in range(samples.shape[1]):
        lo, med, hi = np.percentile(samples[:, i], [16, 50, 84])
        print(med, med - lo, hi - med)

    plt.savefig('../plots/fitDataToModel.pdf')

    plt.show()
Exemplo n.º 3
0
def getMCMCchainForSamplesSize( iSampleSize, nIterations,\
                    hubbleInterpolaterClass,\
                    minimumTimeDelay=0.):
    samples = None
    
    if minimumTimeDelay > 0:
        pklFile = 'picklesMinimumDelay/multiFitSamples_withMass_%i.pkl' \
          % (iSampleSize)
    else:
        pklFile = 'exactPDFpickles/multiFitSamples_withMass_%i.pkl' \
          % iSampleSize
    
    

    if os.path.isfile(pklFile):
        return pkl.load(open(pklFile, 'rb'))
    logProb = np.array([])
    for iIteration in range(nIterations):
        print("Iteration: %i/%i" % (iIteration+1, nIterations))
        selectedTimeDelays = \
              selectRandomSampleOfTimeDelays( iSampleSize, \
                        minimumTimeDelay=minimumTimeDelay)
      
        fitHubbleClass = \
              fitHubble.fitHubbleParameterClass( selectedTimeDelays, \
                                    hubbleInterpolaterClass)

        if samples is None:
            samples = fitHubbleClass.samples
        else:
            samples = np.vstack( (samples, fitHubbleClass.samples))



    pkl.dump(samples, open(pklFile, 'wb'))

    return samples
def getMCMCchainForSamplesSize( iSampleSize, nIterations,\
                    hubbleInterpolaterClass, massCut=0.):
    samples = None

    if massCut > 0:
        pklFile = 'picklesMassCut/multiFitSamples_%i_%0.2f.pkl' \
          % (iSampleSize, massCut)
    else:
        pklFile = 'exactPDFpickles/multiFitSamples_%i.pkl' \
          % iSampleSize
    

    if os.path.isfile(pklFile):
        return pkl.load(open(pklFile, 'rb'))
    
    for iIteration in range(nIterations):
        print("Iteration: %i/%i" % (iIteration+1, nIterations))
        selectedTimeDelays = \
              selectRandomSampleOfTimeDelays( iSampleSize, massCut=massCut)
      
        fitHubbleClass = \
              fitHubble.fitHubbleParameterClass( selectedTimeDelays, \
                                    hubbleInterpolaterClass)

        y, x = np.histogram(fitHubbleClass.samples[:,0])
        xc = (x[1:] + x[:-1])/2.
            
        if samples is None:
            samples = fitHubbleClass.samples
        else:
            samples = np.vstack( (samples, fitHubbleClass.samples))



    pkl.dump(samples, open(pklFile, 'wb'))
        
    return samples