コード例 #1
0
def peak_analysis(activities, room, conf):
    sensors = ["power", "temperature_ds18b20"]
    locations = dict()
    locations["temperature_ds18b20"] = ["wuconditions"]
    if room[0] == "Bedroom":
        locations["power"] = ["brac"]
    else:
        locations["power"] = ["lr"]

    df = data_frame(activities, room, conf, sensors, locations)
    peaks = numpy.array([])

    fig = plt.figure(figsize=(18,12), facecolor='w', edgecolor='k')
    fig.suptitle(room[0] + " Peak Power Analysis", fontsize=14, fontweight='bold')
    idx = 1
    power_cols = filter(lambda x: 'Power' in x, df.columns)
    plots = 100*(numpy.ceil(len(power_cols)/2)+1) + 20
    results = pandas.DataFrame(index=activities)
    for column in power_cols:
        power_df = df[column]
        if len(power_df[power_df < 1500]) == 0:
            clusters = 1
        else:
            clusters = 3

        peak_value, labels = generate_clusters(power_df, clusters = clusters)
        peaks = numpy.append(peaks, peak_value)

        activity = column.split('_')[1]
        val = activity + '_Temperature'
        text_col = filter(lambda x: val in x, df.columns)

        results.loc[activity, "Peak"] = peak_value
        results.loc[activity, "Text_Avg"] = df[text_col[0]].mean()

        ax = plt.subplot(plots + idx)
        scatter_plot(power_df, labels, ax, activity)
        idx = idx + 1

    ax1 = plt.subplot(plots + idx)  # Create matplotlib axes
    results.to_csv('Results/Stats/Raw/' + room[0] + '_Summary.csv')
    yy_plot(results["Peak"], results["Text_Avg"], ax1)

    fig.tight_layout()

    plt.savefig('Results/Figures/Raw/' + room[0] + '_Plot.png')
    return results, df
コード例 #2
0
def main():
    size = 20
    iters = 1000
    Ein_list = []
    Eout_list = []
    for i in range(iters):
        random.seed(i)
        Ein_best = 1.0
        theta_best = 0
        s_best = 0
        print("Iter:", i)
        x = []
        y = []
        while True:
            tmp = get_data()
            if tmp not in x:
                x.append(tmp)
                y.append(flip(sign(tmp)))
                if len(x) == size:
                    break
        for idx in range(size + 1):
            if idx == 0:
                theta = (x[idx] - 1) / 2
            elif idx == size:
                theta = (x[idx - 1] + 1) / 2
            else:
                theta = (x[idx - 1] + x[idx]) / 2
            for s in [-1, 1]:
                error = 0
                for k in range(size):
                    if h(s, x[k], theta) != y[k]:
                        error += 1
                Ein = error / size
                if Ein < Ein_best:
                    Ein_best = Ein
                    theta_best = theta
                    s_best = s
        Eout = 0.5 + 0.3 * s_best * (abs(theta_best) - 1)
        print("Best Ein:", Ein_best, " Best Eout:", Eout)
        Ein_list.append(Ein_best)
        Eout_list.append(Eout)
    print("Mean Ein:", sum(Ein_list) / len(Ein_list))
    print("Mean Eout:", sum(Eout_list) / len(Eout_list))
    plot.scatter_plot(Ein_list, Eout_list)
コード例 #3
0
ファイル: main.py プロジェクト: goffersoft/ml_with_python
def plot_dataset(feature_matrix,
                 output_colvec,
                 dataset_title,
                 dataset_xlabel='X',
                 dataset_ylabel='Y',
                 label=None,
                 plot_image=False,
                 img_size=None,
                 num_images_per_row=None,
                 num_images_per_col=None):
    """Plot data as a scatter diagram."""
    fig = None
    subplot = None
    print('Plotting Data ...')
    yvals = np.unique(output_colvec)
    markers = get_markers(len(yvals))
    colors = get_colors(len(yvals))
    if plot_image:
        random_rows = np.random.randint(
            0, len(output_colvec), num_images_per_row * num_images_per_col)

        def get_img(index):
            return np.reshape(feature_matrix[random_rows[index], 0:-1],
                              newshape=img_size)

        fig, subplot = image_plot(num_images_per_row, num_images_per_col,
                                  get_img)
    else:
        for index, yval in enumerate(yvals):
            fig, subplot = \
                scatter_plot(feature_matrix[(output_colvec == yval).
                                            nonzero(), 1],
                             feature_matrix[
                                 (output_colvec == yval).nonzero(), 2],
                             xlabel=dataset_xlabel,
                             ylabel=dataset_ylabel,
                             title=dataset_title,
                             marker=markers[index], color=colors[index],
                             label=label[index],
                             linewidths=None,
                             fig=fig, subplot=subplot)

    util.pause('Program paused. Press enter to continue.\n')

    return fig, subplot
コード例 #4
0
ファイル: main.py プロジェクト: goffersoft/ml_with_python
def plot_dataset(feature_matrix,
                 output_colvec,
                 num_features,
                 dataset_title,
                 dataset_xlabel='X',
                 dataset_ylabel='Y'):
    """Plot data as a scatter diagram."""
    fig = None
    subplot = None
    if num_features == 1:
        print('Plotting Data ...')
        fig, subplot = \
            scatter_plot(feature_matrix[:, 1], output_colvec,
                         xlabel=dataset_xlabel,
                         ylabel=dataset_ylabel,
                         title=dataset_title,
                         marker='.', color='r',
                         linewidths=0.02,
                         label='Training data')

    util.pause('Program paused. Press enter to continue.\n')

    return fig, subplot
コード例 #5
0
                continue

            if not os.path.exists(params.input.mtz):
                print("input mtz doesn't exsit: {}".format(params.input.mtz))
                continue

            params.exhaustive.output.csv_name = os.path.join(
                params.output.out_dir, "exhaustive_search.csv")

            csv_paths.append(params.exhaustive.output.csv_name)

            if os.path.exists(params.exhaustive.output.csv_name):
                continue

            exhaustive(params=params)
            scatter_plot(params.exhaustive.output.csv_name)

    with open(os.path.join(compound_dir, "es_minima.csv"), "wb") as minima_csv:

        minima_writer = csv.writer(minima_csv, delimiter=",")

        for path in csv_paths:
            occ, u_iso, fofc = get_minimum_fofc(path)
            b_fac = u_iso_to_b_fac(u_iso)

            xtal_name = os.path.split(os.path.split(path)[0])[1]

            minima_writer.writerow([xtal_name, occ, b_fac, fofc])

#### Covalent ratios ###################
コード例 #6
0
# Models to use
MODELS = [Ridge, KNeighborsRegressor]

# Model complexity
COMPLEXITIES = [1.0, 5]

########
# Main #
########

if __name__ == '__main__':
    # Generate data
    X, y = make_data(N_DATASETS * N_SAMPLES, N_IRRELEVANT)

    # Plot data
    scatter_plot(X[:, 0], y, 'Q3d_data')

    # Calculate expected error and its terms for
    # each model
    for model, complexity in zip(MODELS, COMPLEXITIES):
        # Create the protocol
        p = Protocol(X, y)

        # Train models
        p.train(model, complexity, N_DATASETS)

        # Get error and its terms
        noise, s_bias, var, exp_error = p.eval()

        # Plot result
        multi_plot(
コード例 #7
0
import plot
import logistic_regression as lr

data = lr.load_data('iris_data.csv')  # Load the data

plot.scatter_plot(
    data, ['Iris-setosa', 'Iris-versicolor'])  # Scatter plot of the data

X, y = lr.split(data)  # Split into data and labels

X_train, X_test, y_train, y_test = lr.train_test_split(
    X, y)  # Split all the data into training and testing set

theta = lr.SGD(X_train, y_train)  # Run SGD to calculate optimal theta
print('\nCalculated theta:\n {}'.format(theta))

hypothesis = lr.predict(X_test, theta)  # Test the model

lr.accuracy(hypothesis, y_test)

plot.boundary(data, ['Iris-setosa', 'Iris-versicolor'],
              theta)  # Plot the decision boundary
コード例 #8
0
# params.input.mtz = "/dls/science/groups/i04-1/elliot-dev/Work/" \
#                    "exhaustive_search_data/repeat_soaks/2018-05-28/" \
#                    "NUDT22_from_occ_group_with_refinement/" \
#                    "FMOPL000622a_DSI_poised/NUDT22A-x0955/refine.mtz"

params.output.out_dir = ("/dls/science/groups/i04-1/elliot-dev/Work/"
                         "exhaustive_search_data/convex_buffer_tests/"
                         "NUDT7A-x1813")

params.settings.processes = 1

params.exhaustive.output.csv_name = "no_convex_hull.csv"
params.exhaustive.options.convex_hull = False
exhaustive(params=params)
scatter_plot(
    os.path.join(params.output.out_dir, params.exhaustive.output.csv_name),
    three_dim_plot=True,
)

params.exhaustive.options.generate_mtz = True
params.exhaustive.options.convex_hull = True
params.exhaustive.output.csv_name = "convex_hull.csv"
exhaustive(params=params)
scatter_plot(
    os.path.join(params.output.out_dir, params.exhaustive.output.csv_name),
    three_dim_plot=True,
)

params.exhaustive.options.convex_hull = False
params.exhaustive.options.ligand_atom_points = True
params.exhaustive.options.atom_points_sel_string = (
    "(chain E and altid C and resid 1) or (chain E and altid D resid 1)")
コード例 #9
0
# coding: utf-8

import numpy as np
import test_image_ellipsoid as tie
import plot
import bounding_ellipsoid as be
import bounding_box as bb
import basic_functions as bf
import matplotlib.pyplot as plt

ellipsoid = {'a': 100, 'b': 50, 'c': 30}
aggregate = tie.ellipsoid_test_image(ellipsoid,
                                     npoints=10000,
                                     noise_amplitude=10.,
                                     angles=(np.pi / 7., np.pi / 6.))
fig = plot.scatter_plot(aggregate)

bb.bbox_volume(aggregate)
bbox = bb.bbox_optim(aggregate)
print(bbox)
fig = plot.bbox_plot(aggregate, bbox)

rotated_aggregate = bf.rotate_aggregate(aggregate, angles=bbox['angles'])
rotated_bbox = bb.compute_bbox(rotated_aggregate)
fig = plot.bbox_plot(rotated_aggregate, rotated_bbox)

ellipsoid = be.bounding_ellipsoid_optim(aggregate)
plot.fit_ellipsoid_plot(rotated_aggregate, ellipsoid)

ellipsoid = {'a': 100, 'b': 50, 'c': 30}
aggregate = tie.ellipsoid_test_image(ellipsoid,