# RANDU example This example is adapted from Tyler et al. (2009) and illustrates the behavior of ICS on data generated by the well-known RANDU pseudo-random number generator. The way in which RANDU generates its numbers is somewhat deterministic. Upon closer inspection, a structure can be seen in the data, which becomes clearer when the ICS method is applied. The example highlights how ICS is able to identify informative directions associated with these dependencies, in contrast to variance-based approaches such as PCA. ```python from icspylab import ICS, plot_ics from icspylab.distributions import generate_randu from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler import matplotlib.pyplot as plt ``` The dataset is generated using the {func}`icspylab.distributions.generate_randu` function. ```python X = generate_randu() print("X shape:", X.shape) ``` ```text X shape: (400, 3) ``` The plot below illustrates the generated RANDU dataset in three dimensions. ```python fig = plt.figure() ax = fig.add_subplot(projection="3d") ax.scatter(X[:, 0], X[:, 1], X[:, 2], s=2) plt.show() ``` ```{image} ../_static/randu_3d.png :alt: 3D scatter plot of the RANDU dataset :width: 400px :align: center ``` In three-dimensional space, each point represents 3 consecutive pseudorandom values, and it is known that these points fall in one of 15 two-dimensional planes. Applying ICS yields the following invariant components, which clearly exhibit those planes on the last component. ```python ics = ICS(S1="cov", S2="tcovAxis", algorithm="standard") X_ics = ics.fit_transform(X) plot_ics(X_ics) ``` ```{image} ../_static/randu_ics.png :alt: ICS projection on the RANDU dataset :width: 500px :align: center ``` On the contrary, the underlying structure of RANDU is not visible on the first principal components. ```python # Compute the principal components scaler = StandardScaler().set_output(transform="pandas") X_scaled = scaler.fit_transform(X) pca = PCA(n_components=2) X_pca = pca.fit_transform(X_scaled) # Plot the principal components plt.figure(figsize=(5, 5)) plt.scatter(X_pca[:, 0], X_pca[:, 1], alpha=0.7) plt.title("PCA projection of the simulated dataset \n(first two components)") plt.xlabel("Principal component 1") plt.ylabel("Principal component 2") plt.axis("equal") plt.show() ``` ```{image} ../_static/randu_pca.png :alt: PCA projection on the RANDU dataset :width: 500px :align: center ```