<jupyter_start><jupyter_text>It seems that based on these results it should be easy to cluster the data points<jupyter_code>predictions = suite.kcluster(model, numclusters=2, init='random').predict(strain[:,None][:])
elastic, plastic = suite.splitdata(model,predictions)

plot.plotmult2D(elastic,plastic)
suite.get_slopes(model)
#model = elastic (To continue scoping in on elastic region)
predictions = suite.kcluster(model, numclusters=2, init='random').predict(strain[:,None][:])
plot.plotmult2D(suite.combine_data(model[:,0],suite.get_slopes(model)),plastic)<jupyter_output><empty_output><jupyter_text>This seems erroneous so let's look at the slopes that it believes are part of the same group<jupyter_code>elastic_slope, plastic_slope = suite.splitdata(strainvslope, predictions)
plot.plotmult2D(elastic_slope,plastic_slope)<jupyter_output><empty_output><jupyter_text>Once the data slope begins decreasing, if we are far enough along we can say with confidence that yield is beginning<jupyter_code>standard_deviation = np.std(slopes[:len(slopes)/4])
print standard_deviation
yield_spot = 0

for index, slope in enumerate(slopes):
    
    if slope<-20 and index>(len(slopes)/4.):
        if slopes[index+1]<-20:
            yield_spot=index
            break
        
#print strain[yield_spot],stress[yield_spot]
#print slopes      
# -- this value needs to be high enough to get a good value, but low enough to avoid noisy data
num_intervals = 10

# -- divide into ten intervals and print stddev of each
divs = [np.std(vals) for vals in np.array_split(slopes,num_intervals)]

# -- stdev of the whole thing
stdev = np.std(slopes)

interval = 0
while divs[interval] > stdev:
    interval = interval + 1
    
# -- selects a point halfway in the interval
interval_length = len(model)/num_intervals
yield_index = ((int)(interval_length*interval*3./2.))

    
# -- found yield strain (ONLY TENTATIVELY WORKS -- REFINE THIS)
yield_strain = strain[yield_index]
yield_stress = stress[yield_index]

print divs
yielding = np.array([yield_strain,yield_stress])
print yielding

plot.plotmult2D(model,yielding[None,:],marker2='ro')<jupyter_output>[ 0.08134057  6.82299987]<jupyter_text>The model is still highly subject to fluctuations from the number of intervals, and we need to select a place where the slope is negative mostly throughout the interval, and the standard deviation begins to decrease<jupyter_code># -- we think that yield occurs where the standard deviation is decreasing AND the slopes are mostly negative
def findYieldInterval(slopes, numberofsections):
    
    def numneg(val):
        return sum((val<0).astype(int))
    
    # -- divide into ten intervals and save stddev of each
    splitslopes = np.array_split(slopes,numberofsections)
      
    # -- displays the number of negative values in a range (USEFUL!!!)
    for section in splitslopes:
        print numneg(section), len(section)

    divs = [np.std(vals) for vals in splitslopes]
    
    # -- stddev of the whole thing
    stdev = np.std(slopes)
    
    interval = 0
    sect = splitslopes[interval]
    
    while divs[interval] > stdev or numneg(sect)<5*len(sect)/8:
        
        interval = interval + 1
        
        """Guard against going out of bounds"""
        if interval==len(splitslopes): break
            
        sect = splitslopes[interval]                                         
    
    print interval
    return interval

numberofsections = 15
interval_length = len(model)/numberofsections

"""
Middle of selected interval

Guard against going out of bounds
"""
yield_interval = findYieldInterval(slopes,numberofsections)
yield_index = min(yield_interval*interval_length + interval_length/2,len(strain)-1) 
yield_value = np.array([strain[yield_index],stress[yield_index]])[None,:]

print yield_value
plot.plotmult2D(model,yield_value)<jupyter_output><empty_output><jupyter_text>Now we need to create a function that automatically determines the slopes from the data, calls the other function, and returns the appropriate values<jupyter_code>"""Yield occurs where the standard deviation is decreasing AND the slopes are mostly negative"""
def findYieldInterval(slopes, numberofsections):
    
    def numneg(val):
        return sum((val>0).astype(int))
    
    """Divide into ten intervals and save stddev of each"""
    splitslopes = np.array_split(slopes,numberofsections)
    divs = [np.std(vals) for vals in splitslopes]
    
    """Computes the reference standard deviation"""
    stdev = np.std(slopes)
    
    interval = 0
    sect = splitslopes[interval]
    
    while divs[interval] > stdev or numneg(sect)<3*len(sect)/4:
        
        interval = interval + 1
        
        """Guard against going out of bounds"""
        if interval==len(splitslopes): break
            
        sect = splitslopes[interval]                                         
    
    return interval

"""Returns yield value from a set of experimental data"""
def findYieldValue(model):
    
    """Separate appropriate values"""
    strain = model[:,0]
    stress = model[:,1]
    slopes = []

    """Approximating the partial derivatives of stress/strain"""
    for index in xrange(len(stress)-1):
        slopes.append((stress[index+1]-stress[index])/(strain[index+1]-strain[index]))
        
    print slopes
    """How many sections to create, depends on noisiness and courseness of data"""
    numberofsections = 10
    interval_length = len(model)/numberofsections
        
    """Middle of selected interval"""
    yield_index = findYieldInterval(slopes,numberofsections)*interval_length*3/2 
    yield_value = np.array([strain[yield_index],stress[yield_index]])[None,:]
    
    return yield_value

"""Plots data with superimposed yield value"""
def plotYieldValue(model):
    
    import graph_suite
    graph_suite.plotmult2D(model,findYieldValue(model))

#model1 = strainmodel('ref/HSRS/22').get_experimental_data()
model2 = strainmodel('ref/HSRS/222').get_experimental_data()
model3 = strainmodel('ref/HSRS/326').get_experimental_data()

#plotYieldValue(model1)
plotYieldValue(model3)<jupyter_output>[inf, -inf, inf, inf, -inf, nan, -inf, inf, -inf, inf, -inf, -inf, inf, -inf, inf, -inf, inf, inf, -inf, inf, -inf, inf, -inf, -inf, inf, -inf, inf, inf, -inf, inf, -inf, -inf, inf, inf, -inf, nan, inf, -inf, inf, -inf, -inf, inf, -inf, inf, -inf, inf, -inf, inf, inf, inf, -inf, inf, -inf, inf, -inf, inf, -inf, inf, -inf, inf, inf, -inf, inf, -inf, -inf, -inf, inf, inf, -inf, inf, -inf, inf, inf, -28.699912864328219, -79.392346245671504, -52.709914673414829, -114.57732916889127, -88.282900866978196, -86.320052208296289, -4928.440755382383, -39.723443389744929, -55.976693165434739, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, inf, -inf, inf, 314.13098855493672, -21.618471601818847, 124.39910888092849, -43.505904207266589, 65.816804901101065, 19.262341082263891, -9.8120107969432979, 84.542401728355628, 88.635783376324554, 45.946180707138481, 49.993505411850464, 89.213297682557652, 103.45143806165508[...]<jupyter_text>Working, but we need to clean up issues with special indices and with illegitimate data<jupyter_code>%matplotlib inline

from irreversible_stressstrain import StressStrain as strainmodel
import numpy as np

"""Yield occurs where the standard deviation is decreasing AND the slopes are mostly negative"""
def findYieldInterval(slopes, numberofsections):
    
    def numneg(val):
        return sum((val<0).astype(int))
    
    """Divide into ten intervals and save stddev of each"""
    splitslopes = np.array_split(slopes,numberofsections)
    divs = [np.std(vals) for vals in splitslopes]
    
    """Computes the reference standard deviation"""
    stdev = np.std(slopes)
    
    interval = 0
    sect = splitslopes[interval]
    
    while divs[interval] > stdev or numneg(sect)<3*len(sect)/4:
        
        interval = interval + 1
        
        """Guard against going out of bounds"""
        if interval==len(splitslopes): break
            
        sect = splitslopes[interval]                                         
    
    return interval

"""Returns yield value from a set of experimental data"""
def findYieldValue(model):
    
    """Separate appropriate values"""
    strain = model[:,0]
    stress = model[:,1]
    slopes = []

    """Approximating the partial derivatives of stress/strain"""
    for index in xrange(len(stress)-1):
        
        newslope = (stress[index+1]-stress[index])/(strain[index+1]-strain[index])
                    
        if np.isnan(newslope) or np.isinf(newslope):
            newslope = 0
                                                   
        slopes.append(newslope)
    
    print slopes
    
    """How many sections to create, depends on noisiness and courseness of data"""
    numberofsections = 10
    interval_length = len(model)/numberofsections
        
    """Middle of selected interval"""
    yield_index = findYieldInterval(slopes,numberofsections)*interval_length*3/2 
    yield_value = np.array([strain[yield_index],stress[yield_index]])[None,:]
    
    return yield_value

"""Plots data with superimposed yield value"""
def plotYieldValue(model):
    
    import graph_suite
    graph_suite.plotmult2D(model,findYieldValue(model))

model1 = strainmodel('ref/HSRS/22').get_experimental_data()
model2 = strainmodel('ref/HSRS/222').get_experimental_data()
model3 = strainmodel('ref/HSRS/326').get_experimental_data()

plotYieldValue(model1)
plotYieldValue(model2)
plotYieldValue(model3)<jupyter_output>[555.50353242616472, -1052.6026184028797, -2297.3848942825398, 4691.5387672458819, -3401.9768639915055, 4977.2452344043177, -506.37934248574243, -526.5482410566417, 151.27434089289167, 0.042987490128562886, -7876.1458615485762, 5740.9851212577869, -10683.964792260265, 16239.143081132101, 2225.335752947286, 3797.0397615604656, -384.13788967865077, -1039.9036107769214, -2419.868132251007, 939.97549181577313, -2012.9378702992724, 2525.3515925629658, -536.59213189056868, -624.99730468081634, 262.79827821435168, 579.82460600633488, 970.73894920172552, -101.64804588287438, 48.433579792949487, 429.86489881516724, -1479.0671376894788, 765.93941818323003, -40.285076702862881, -378.59233258598562, 697.46614470709358, -480.68361339745047, 645.1063767490474, -135.52393607530644, 309.73531177091991, 203.46506839484192, -200.62619401120457, 216.41804006909018, -39.710304437378866, 99.47690269798872, 153.99717241031917, -95.871659511364413, 58.063287988629995, -19.754100600340834, 240.29557493401185,[...]
{'fraction_non_alphanumeric': 0.11161345012715457, 'fraction_numerical': 0.12348120938118112, 'mean_word_length': 3.8219800181653043, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '191034', 'license': 'MIT', 'n_tokens_mistral': 4358, 'n_tokens_neox': 3459, 'n_words': 857, 'path': 'devel/Grouping Data by Slope.ipynb', 'repo_name': 'snesnehne/MatPy', 'size': '10617'}