Ask Your Question
1

Why doesn't the SageMath function find_local_maximum work for me in Python?

asked 2020-08-27 16:50:02 -0500

user90664 gravatar image

The code below works in CoCalc, but I can't get it to run in Python in my IDE. I've imported numpy and sagemath, and referred to each as needed to define the math functions, but I can't get the find_local_maximum function to work. See below.

Code:

import numpy as np
import sagemath as sm

def mean_x(factor, values):
    return sum([np.cos(2*np.pi*v/factor) for v in values])/len(values)

def mean_y(factor, values):
    return sum([np.sin(2*np.pi*v/factor) for v in values])/len(values)

def calculatePeriodAppeal(factor, values):
    mx = mean_x(factor, values)
    my = mean_y(factor, values)
    appeal = np.sqrt(mx**2+my**2)
    return appeal

def calculateBestLinear(factor, values):
    mx = mean_x(factor, values).n()
    my = mean_y(factor, values).n()
    y0 = factor*np.atan2(my,mx)/(2*np.pi).n()
    err = 1-np.sqrt(mx**2+my**2).n()
    return [factor*x + y0, err]

def calculateGCDAppeal(factor, values):
    mx = mean_x(factor, values)
    my = mean_y(factor, values)
    appeal = 1 - np.sqrt((mx-1)**2+my**2)/2
    return appeal

testSeq = [552,827,275,809,534] 
gcd = calculateGCDAppeal(x, testSeq)
agcd = sm.find_local_maximum(gcd,20,30)
print(agcd)
np.plot(gcd,(x, 20,30))

Error:

Traceback (most recent call last):

  File "<ipython-input-163-fecb5397afab>", line 31, in <module>
    agcd = sm.find_local_maximum(gcd,20,30)

AttributeError: module 'sagemath' has no attribute 'find_local_maximum'
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-08-27 19:38:26 -0500

slelievre gravatar image

It would seem you ran pip install sagemath which installs the "sagemath" package from PyPI:

That is a dummy package and by doing that you did not install SageMath.

To access SageMath functionality you need to actually install SageMath, not the dummy "sagemath" package from PyPI.

edit flag offensive delete link more

Comments

@slelievre I've now download and installed the .dmg file. The installation guide says to then "Simply use it." How do I use it in an IDE (Spyder or Jupyter notebook)?

user90664 gravatar imageuser90664 ( 2020-08-31 15:06:30 -0500 )edit

More on this as an answer to the follow-up dedicated question:

slelievre gravatar imageslelievre ( 2020-09-01 10:07:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-08-27 16:50:02 -0500

Seen: 73 times

Last updated: Aug 27