예제 #1
0
파일: pca.py 프로젝트: mrawls/Starfish
    def plot_block(block):
        # block specifies the parameter grid points
        # fblock defines a parameter grid that is finer spaced than the gridpoints

        # Query for the weights at the grid points.
        ww = np.empty((len(block), my_pca.m))
        for i,param in enumerate(block):
            weights = my_pca.get_weights(param)
            ww[i, :] = weights

        # Determine the active dimension by finding the one that has unique > 1
        uni = np.array([len(np.unique(block[:, i])) for i in range(len(Starfish.parname))])
        active_dim = np.where(uni > 1)[0][0]

        ublock = block.copy()
        ablock = ublock[:,active_dim]
        ublock = np.delete(ublock, active_dim, axis=1)
        nactive = len(ablock)

        fblock = []
        for par in ublock[0, :]:
            # Create a space of the parameter the same length as the active
            fblock.append(par * np.ones((npoints,)))

        # find min and max of active dim. Create a linspace of `npoints` spanning from
        # min to max
        active = np.linspace(ablock[0], ablock[-1], npoints)

        fblock.insert(active_dim, active)
        fgrid = np.vstack(fblock).T

        # Draw multiple times at the location.
        weight_draws = []
        for i in range(ndraw):
            weight_draws.append(emulator.draw_many_weights(fgrid))

        # Now make all of the plots
        for eig_i in range(my_pca.m):
            fig, ax = plt.subplots(nrows=1, figsize=(6,6))

            x0 = block[:, active_dim] # x-axis
            # Weight values at grid points
            y0 = ww[:, eig_i]
            ax.plot(x0, y0, "bo")

            x1 = fgrid[:, active_dim]
            for i in range(ndraw):
                y1 = weight_draws[i][:, eig_i]
                ax.plot(x1, y1)

            ax.set_ylabel(r"$w_{:}$".format(eig_i))
            ax.set_xlabel(Starfish.parname[active_dim])

            fstring = "w{:}".format(eig_i) + Starfish.parname[active_dim] + "".join(["{:.1f}".format(ub) for ub in ublock[0, :]])

            fig.savefig(Starfish.config["plotdir"] + fstring + ".png")

            plt.close('all')
예제 #2
0
파일: pca.py 프로젝트: norrisryan/Starfish
    def plot_block(block):
        # block specifies the parameter grid points
        # fblock defines a parameter grid that is finer spaced than the gridpoints

        # Query for the weights at the grid points.
        ww = np.empty((len(block), my_pca.m))
        for i,param in enumerate(block):
            weights = my_pca.get_weights(param)
            ww[i, :] = weights

        # Determine the active dimension by finding the one that has unique > 1
        uni = np.array([len(np.unique(block[:, i])) for i in range(len(Starfish.parname))])
        active_dim = np.where(uni > 1)[0][0]

        ublock = block.copy()
        ablock = ublock[:,active_dim]
        ublock = np.delete(ublock, active_dim, axis=1)
        nactive = len(ablock)

        fblock = []
        for par in ublock[0, :]:
            # Create a space of the parameter the same length as the active
            fblock.append(par * np.ones((npoints,)))

        # find min and max of active dim. Create a linspace of `npoints` spanning from
        # min to max
        active = np.linspace(ablock[0], ablock[-1], npoints)

        fblock.insert(active_dim, active)
        fgrid = np.vstack(fblock).T

        # Draw multiple times at the location.
        weight_draws = []
        for i in range(ndraw):
            weight_draws.append(emulator.draw_many_weights(fgrid))

        # Now make all of the plots
        for eig_i in range(my_pca.m):
            fig, ax = plt.subplots(nrows=1, figsize=(6,6))

            x0 = block[:, active_dim] # x-axis
            # Weight values at grid points
            y0 = ww[:, eig_i]
            ax.plot(x0, y0, "bo")

            x1 = fgrid[:, active_dim]
            for i in range(ndraw):
                y1 = weight_draws[i][:, eig_i]
                ax.plot(x1, y1)

            ax.set_ylabel(r"$w_{:}$".format(eig_i))
            ax.set_xlabel(Starfish.parname[active_dim])

            fstring = "w{:}".format(eig_i) + Starfish.parname[active_dim] + "".join(["{:.1f}".format(ub) for ub in ublock[0, :]])

            fig.savefig(Starfish.config["plotdir"] + fstring + ".png")

            plt.close('all')