OrbitsDataset and OrbitsDataModule

Orbits dataset.

Functions


source

create_orbits_dataframe

 create_orbits_dataframe (n_orbits:int=5, n_points:int=400,
                          width:numbers.Number=0.2, noise_level:float=0.0,
                          label_by_distance:bool=True,
                          n_classes:Optional[int]=5,
                          label_key:str='label', use_index:bool=True)

source

create_orbits_dataset

 create_orbits_dataset (n_orbits:int, n_points:int,
                        width:numbers.Number=0.2, noise_level:float=0.0,
                        label_by_distance:bool=True,
                        n_classes:Optional[int]=5)

Generates a dataset of orbits.


source

categorize_distances

 categorize_distances (distances:NDArray[Shape['*'],Float], n_classes:int)

Categorizes distances into n_classes classes.


source

distance_from_origin

 distance_from_origin (points:NDArray[Shape['*,[x,y]'],Float])

Calculates distance of points from the origin.


source

rotate_orbit

 rotate_orbit (orbit:NDArray[Shape['*,[x,y]'],Float],
               rotation_angle:float)

Rotates an orbit by a given angle.


source

make_orbit

 make_orbit (n_points:int, width:numbers.Number=0.2)

Generates an orbit.

Args: n_points: number of points in the orbit width: width of the orbit

Returns: orbit: the orbit as a numpy array of shape (n_points, 2)

df = create_orbits_dataframe(5, 400, .25, noise_level=.025, label_by_distance=True, n_classes=5)
df.head()
x y
label
4 0.986363 0.024106
4 0.995865 -0.015601
4 1.022529 -0.001975
4 1.002284 0.012532
4 0.978433 0.003777
plt.figure(figsize=(4, 4))
sns.scatterplot(data=df, x='x', y='y', hue='label', palette='Set2')
plt.show()

Dataset


source

OrbitsDataset

 OrbitsDataset (*args, **kwargs)
dd = OrbitsDataset()
dd.getone()
(tensor([[-0.0875, -0.1872],
         [ 0.2494, -0.3807],
         [-0.4403, -0.4955],
         [ 0.7146,  0.4166],
         [ 0.3441, -0.8967]]),
 tensor([0., 1., 2., 3., 4.]))
dd.plot(palette='mako_r')

DataModule


source

OrbitsDataModule

 OrbitsDataModule (df:pandas.core.frame.DataFrame=<factory>,
                   n_orbits:int=5, n_points:int=400,
                   width:numbers.Number=0.2, noise_level:float=0.025,
                   label_by_distance:bool=True, n_classes:Optional[int]=5,
                   perc_train:float=0.7, perc_valid:float=0.1,
                   perc_test:float=0.2, include_time:Optional[bool]=False,
                   device:Optional[littyping.device.Device]=None)

Example

ddm = OrbitsDataModule()
ddm.prepare_data()
OrbitsDataModule(n_orbits=5, n_points=400, width=0.2, noise_level=0.025, label_by_distance=True, n_classes=5, perc_train=0.7, perc_valid=0.1, perc_test=0.2, include_time=False, device=None)
ddm.setup()
train_dl = ddm.train_dataloader()
for batch in train_dl:
    break
batch[0].shape, batch[1].shape
(torch.Size([64, 5, 2]), torch.Size([64, 5]))
len(ddm.idxs_train), len(ddm.idxs_valid), len(ddm.idxs_test)
(1400, 200, 400)
ddm.train_ds.df.shape
(2000, 3)