Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzy Option in RCMSE #1066

Open
typn-git opened this issue Jan 31, 2025 · 3 comments
Open

Fuzzy Option in RCMSE #1066

typn-git opened this issue Jan 31, 2025 · 3 comments

Comments

@typn-git
Copy link

Hi, thank you for your great work on NeuroKit2!

I am trying to calculate RCMSE using NeuroKit2. To examine the effect of the fuzzy option, I applied both complexity_rcmse() and complexity_fuzzyrcmse() to the same EEG data, but both returned almost identical results.

After checking the source code of entropy_multiscale, I noticed that in CMSE, the _phi() function receives the fuzzy flag via **kwargs, but in RCMSE, it does not seem to be passed to _phi().

entropy_multiscale.py

else:
    # CMSE
    if refined is False:
        return _validmean(
            [
                algorithm(
                    coarse[i],
                    delay=1,
                    dimension=dimension,
                    tolerance=tolerance,
                    **kwargs,
                )[0]
                for i in range(len(coarse))
            ]
        )
    # RCMSE
    else:
        phis = np.array(
            [
                _phi(
                    coarse[i],
                    delay=1,
                    dimension=dimension,
                    tolerance=tolerance,
                    approximate=False,
                )[0]
                for i in range(len(coarse))
            ]
        )
        # Average all phi of the same dimension, then divide, then log
        return _phi_divide([_validmean(phis[:, 0]), _validmean(phis[:, 1])])`

How is the fuzzy flag handled in RCMSE?
Thanks in advance!

Copy link

welcome bot commented Jan 31, 2025

Hi 👋 Thanks for reaching out and opening your first issue here! We'll try to come back to you as soon as possible. ❤️ kenobi

@DominiqueMakowski
Copy link
Member

Mh could you please run some tests to see if it indeed the results between fuzzy and non-fuzzy are the same (which if I understand you suggest might be happening?) we can help see if indeed there's something wrong

@typn-git
Copy link
Author

typn-git commented Feb 4, 2025

@DominiqueMakowski Thank you for your response.

I compared CMSE and RCMSE with and without the fuzzy option using simulated data. In CMSE, the fuzzy option significantly changed the values, but in RCMSE, the values remained the same.

import matplotlib.pyplot as plt
import neurokit2 as nk
signal1 = nk.signal_simulate(duration=2, frequency=[5, 12, 40])
cmsen1_noFuzzy, cmsen1_noFuzzy_info = nk.entropy_multiscale(signal1, method="CMSEn", show=False, fuzzy=False)
cmsen1_Fuzzy, cmsen1_Fuzzy_info = nk.entropy_multiscale(signal1, method="CMSEn", show=False, fuzzy=True)
plt.plot(cmsen1_noFuzzy_info["Value"], label="CMSE noFuzzy")
plt.plot(cmsen1_Fuzzy_info["Value"], label="CMSE Fuzzy")

plt.legend()

plt.xlabel("Scale")
plt.ylabel("Value")

plt.title("Comparison of noFuzzy and Fuzzy Values of CMSE")

plt.savefig("CMSE_comparison.png")
plt.show()

Image

rcmsen1_noFuzzy, rcmsen1_noFuzzy_info = nk.entropy_multiscale(signal1, method="RCMSEn", show=False, fuzzy=False)
rcmsen1_Fuzzy, rcmsen1_Fuzzy_info = nk.entropy_multiscale(signal1, method="RCMSEn", show=False, fuzzy=True)
plt.plot(rcmsen1_noFuzzy_info["Value"], label="RCMSE noFuzzy")
plt.plot(rcmsen1_Fuzzy_info["Value"], label="RCMSE Fuzzy")

plt.legend()

plt.xlabel("Scale")
plt.ylabel("Value")

plt.title("Comparison of noFuzzy and Fuzzy Values of RCMSE")

plt.savefig("RCMSE_comparison.png")
plt.show()

Image

As an experiment, I modified entropy_multiscale.py to pass **kwargs as an argument when calling the _phi() function in RCMSE.

        # RCMSE
        else:
            phis = np.array(
                [
                    _phi(
                        coarse[i],
                        delay=1,
                        dimension=dimension,
                        tolerance=tolerance,
                        approximate=False,
                        **kwargs,  #Add
                    )[0]
                    for i in range(len(coarse))
                ]
            )
            # Average all phi of the same dimension, then divide, then log
            return _phi_divide([_validmean(phis[:, 0]), _validmean(phis[:, 1])])

After making this change and performing the same calculation, the values in RCMSE changed by fuzzy option.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants