<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Experiment Details
I will first analyze the data where each of the Pis were placed at origin.
This experiment's data was collected at 2
Step1:  Preliminary Conclusions
As we can see here, the data for device 68
Step2:  Looking at the distribution of data points, it looks like it will be difficult for us to resolve distances less than 24 ft.
I think a second experiment is in order.
<ASSISTANT_TASK:>
Python Code:
# Let's plot the data for each of the devices, from each of the base stations.
dfs = [(origin, 'origin'), (eastern, 'eastern'), (southern, 'southern')]
def plot_signal_vs_distance(device):
    fig = plt.figure(figsize=(9,3))
    ax1 = fig.add_subplot(131)
    ax2 = fig.add_subplot(132)
    ax3 = fig.add_subplot(133)
    axes = [ax1, ax2, ax3]
    for i, (df, title) in enumerate(dfs):
        df.dropna().query('tracker_id=="{0}"'.format(device)).plot(x='distance', y='dB', kind='scatter', ax=axes[i])
        axes[i].set_title(title)
    plt.tight_layout()
device = '68:9E:19:11:A6:DB'
plot_signal_vs_distance(device)
device = 'F4:B8:5E:C4:56:22'
plot_signal_vs_distance(device)
Explanation: Experiment Details
I will first analyze the data where each of the Pis were placed at origin.
This experiment's data was collected at 2:42 pm, and ended at 3:21 pm.
In this experiment, Nichola and Jon moved from 0 ft to 48 ft away from origin.
End of explanation
# In order to have more data put together, I will concatenate the 3 data frames.
device = '68:9E:19:11:A6:DB'
# device = 'F4:B8:5E:C4:56:22'
all_data = origin.dropna().append(eastern.dropna()).append(southern.dropna()).query('tracker_id=="{0}"'.format(device))
all_data.plot(x='distance', y='dB', kind='scatter', title='{0} data points'.format(len(all_data)))
sns.violinplot(x=all_data['distance'], y=all_data['dB'])
Explanation: Preliminary Conclusions
As we can see here, the data for device 68:9E:19:11:A6:DB was much better than the device F4:B8:5E:C4:56:22. There seems to be a stronger correlation with distance on device 68 than device F4. I will attempt Bayesian modelling to quantify the uncertainty around each distance measurement for device 68.
End of explanation
import pymc3 as pm
with pm.Model() as model:
    # Hyperparameters for A and B
    # mu_a = pm.Normal('mu_A', mu=0, sd=10)
    # sig_a = pm.Uniform('sigma_A', lower=0, upper=10)
    
    # mu_b = pm.Normal('mu_B', mu=0, sd=10)
    # sig_b = pm.Uniform('sigma_B', lower=0, upper=10)
    
    # Estimate the intercepts
    A = pm.Normal('A', mu=-0.2, sd=3)
    B = pm.Normal('B', mu=-50, sd=3)
    
    # Error term
    err = pm.Normal('error', mu=-30, sd=10)
    
    # Model prediction:
    dB = A * all_data['distance'] + B + err
    
    # dB likelihood
    db_like = pm.Normal('dB', mu=dB, sd=10, observed=all_data['dB'])
with model:
    start = pm.find_MAP()
    step = pm.NUTS()
    trace = pm.sample(10000, step)
pm.traceplot(trace)
pm.summary(trace)
Explanation: Looking at the distribution of data points, it looks like it will be difficult for us to resolve distances less than 24 ft.
I think a second experiment is in order.
End of explanation
<END_TASK>