Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lestes1118 authored Jun 17, 2024
1 parent e32fb61 commit 56e21c9
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions cmeutils/piecewise linear regression.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9bea9844-da81-4bcc-922e-743f62a968aa",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import piecewise_regression \n",
"#pip install piecewise-regression \n",
"#https://github.com/chasmani/piecewise-regression.git\n",
"\n",
"x = np.load(\"your_file.npy\")\n",
"y = np.load(\"your_file.npy\")\n",
"\n",
"plt.plot(x, y, \"o-\")\n",
"plt.xlabel('x_label')\n",
"plt.ylabel('y_label')\n",
"plt.title('Knee method to sovle for Tg')\n",
"\n",
"pw_fit = piecewise_regression.Fit(x, y, n_breakpoints=1)\n",
"pw_fit.plot_breakpoints(color='r')\n",
"\n",
"\n",
"def find_tg(x,y):\n",
" results=pw_fit.get_results()\n",
" Tg=results['estimates']['breakpoint1']['estimate']\n",
" return Tg\n",
"\n",
"Tg=find_tg(x,y)\n",
"print('Glass transition temperature is:',Tg)\n",
"\n",
"def find_slope1(x,y):\n",
" results=pw_fit.get_results()\n",
" slope1=results['estimates']['alpha1']['estimate']\n",
" return slope1\n",
"\n",
"slope1=find_slope1(x,y)\n",
"print('Slope before breakpoint1 is:',slope1)\n",
"\n",
"def find_slope2(x,y):\n",
" results=pw_fit.get_results()\n",
" slope2=results['estimates']['beta1']['estimate']\n",
" return slope2\n",
"\n",
"slope2=find_slope2(x,y)\n",
"print('Slope after breakpoint1 is:',slope2)\n",
"\n",
"# Print a summary of the fit\n",
"pw_fit.summary()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 56e21c9

Please sign in to comment.