Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Razdoburdin committed Jul 27, 2023
1 parent 2f037f6 commit 8644612
Show file tree
Hide file tree
Showing 71 changed files with 1,052 additions and 793 deletions.
17 changes: 9 additions & 8 deletions examples/daal4py/adaboost.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py Adaboost example for shared memory systems

Expand All @@ -25,14 +25,15 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
infile = "./data/batch/adaboost_train.csv"
testfile = "./data/batch/adaboost_test.csv"
nClasses = 2
Expand All @@ -56,7 +57,7 @@ def main(readcsv=read_csv, method='defaultDense'):

# The prediction result provides prediction
assert predict_result.prediction.shape == (pdata.shape[0], dep_data.shape[1])
ptdata = np.loadtxt(testfile, usecols=range(20, 21), delimiter=',', ndmin=2)
ptdata = np.loadtxt(testfile, usecols=range(20, 21), delimiter=",", ndmin=2)
assert np.allclose(predict_result.prediction, ptdata)

return (train_result, predict_result, ptdata)
Expand All @@ -67,6 +68,6 @@ def main(readcsv=read_csv, method='defaultDense'):
print("\nGround truth (first 20 observations):\n", ptdata[:20])
print(
"Adaboost classification results: (first 20 observations):\n",
predict_result.prediction[:20]
predict_result.prediction[:20],
)
print('All looks good!')
print("All looks good!")
25 changes: 14 additions & 11 deletions examples/daal4py/adagrad_mse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py AdaGrad (Adaptive Subgradient Method) example for shared memory systems
# using Mean Squared Error objective function
Expand All @@ -26,14 +26,15 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
infile = "./data/batch/mse.csv"
# Read the data, let's have 3 independent variables
data = readcsv(infile, range(3))
Expand All @@ -47,11 +48,13 @@ def main(readcsv=read_csv, method='defaultDense'):
# configure an AdaGrad object
lr = np.array([[1.0]], dtype=np.double)
niters = 1000
sgd_algo = d4p.optimization_solver_adagrad(mse_algo,
learningRate=lr,
accuracyThreshold=0.0000001,
nIterations=niters,
batchSize=1)
sgd_algo = d4p.optimization_solver_adagrad(
mse_algo,
learningRate=lr,
accuracyThreshold=0.0000001,
nIterations=niters,
batchSize=1,
)

# finally do the computation
inp = np.array([[8], [2], [1], [4]], dtype=np.double)
Expand All @@ -67,4 +70,4 @@ def main(readcsv=read_csv, method='defaultDense'):
res = main()
print("\nMinimum:\n", res.minimum)
print("\nNumber of iterations performed:\n", res.nIterations[0][0])
print('All looks good!')
print("All looks good!")
15 changes: 8 additions & 7 deletions examples/daal4py/association_rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py assiciation rules example for shared memory systems

Expand All @@ -25,14 +25,15 @@
import pandas

def read_csv(f, c=None, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c=None, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
infile = "./data/batch/apriori.csv"

# configure a association_rules object
Expand All @@ -58,6 +59,6 @@ def main(readcsv=read_csv, method='defaultDense'):

if __name__ == "__main__":
result1 = main()
print('Confidence: (20 first)')
print("Confidence: (20 first)")
print(result1.confidence[0:20])
print('All looks good!')
print("All looks good!")
13 changes: 7 additions & 6 deletions examples/daal4py/bacon_outlier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py outlier detection bacon example for shared memory systems

Expand All @@ -25,14 +25,15 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
# Input file
infile = "./data/batch/outlierdetection.csv"

Expand All @@ -56,4 +57,4 @@ def main(readcsv=read_csv, method='defaultDense'):

print("\nInput data\n", data)
print("\nOutlier detection result (Bacon method) weights:\n", res.weights)
print('All looks good!')
print("All looks good!")
18 changes: 9 additions & 9 deletions examples/daal4py/bf_knn_classification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py Brute Force KNN example for shared memory systems

Expand All @@ -27,17 +27,18 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
# Input data set parameters
train_file = os.path.join('data', 'batch', 'k_nearest_neighbors_train.csv')
predict_file = os.path.join('data', 'batch', 'k_nearest_neighbors_test.csv')
train_file = os.path.join("data", "batch", "k_nearest_neighbors_train.csv")
predict_file = os.path.join("data", "batch", "k_nearest_neighbors_test.csv")

# Read data. Let's use 5 features per observation
nFeatures = 5
Expand Down Expand Up @@ -71,6 +72,5 @@ def main(readcsv=read_csv, method='defaultDense'):
print("Brute Force kNN classification results:")
print("Ground truth(observations #30-34):\n", predict_labels[30:35])
print(
"Classification results(observations #30-34):\n",
predict_result.prediction[30:35]
"Classification results(observations #30-34):\n", predict_result.prediction[30:35]
)
17 changes: 9 additions & 8 deletions examples/daal4py/brownboost.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py Brownboost example for shared memory systems

Expand All @@ -25,14 +25,15 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
infile = "./data/batch/brownboost_train.csv"
testfile = "./data/batch/brownboost_test.csv"

Expand All @@ -55,7 +56,7 @@ def main(readcsv=read_csv, method='defaultDense'):

# The prediction result provides prediction
assert predict_result.prediction.shape == (pdata.shape[0], dep_data.shape[1])
ptdata = np.loadtxt(testfile, usecols=range(20, 21), delimiter=',', ndmin=2)
ptdata = np.loadtxt(testfile, usecols=range(20, 21), delimiter=",", ndmin=2)
assert np.allclose(predict_result.prediction, ptdata)

return (train_result, predict_result, ptdata)
Expand All @@ -66,6 +67,6 @@ def main(readcsv=read_csv, method='defaultDense'):
print("\nGround truth (first 20 observations):\n", ptdata[:20])
print(
"Brownboost classification results: (first 20 observations):\n",
predict_result.prediction[:20]
predict_result.prediction[:20],
)
print('All looks good!')
print("All looks good!")
13 changes: 7 additions & 6 deletions examples/daal4py/cholesky.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py cholesky example for shared memory systems

Expand All @@ -25,14 +25,15 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
def main(readcsv=read_csv, method="defaultDense"):
infile = "./data/batch/cholesky.csv"

# configure a cholesky object
Expand All @@ -46,4 +47,4 @@ def main(readcsv=read_csv, method='defaultDense'):
if __name__ == "__main__":
result = main()
print("\nFactor:\n", result.choleskyFactor)
print('All looks good!')
print("All looks good!")
17 changes: 9 additions & 8 deletions examples/daal4py/correlation_distance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright 2014 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# ===============================================================================

# daal4py correlation distance example for shared memory systems

Expand All @@ -27,21 +27,22 @@
import pandas

def read_csv(f, c, t=np.float64):
return pandas.read_csv(f, usecols=c, delimiter=',', header=None, dtype=t)
return pandas.read_csv(f, usecols=c, delimiter=",", header=None, dtype=t)

except ImportError:
# fall back to numpy loadtxt
def read_csv(f, c, t=np.float64):
return np.loadtxt(f, usecols=c, delimiter=',', ndmin=2)
return np.loadtxt(f, usecols=c, delimiter=",", ndmin=2)


def main(readcsv=read_csv, method='defaultDense'):
data = readcsv(os.path.join('data', 'batch', 'distance.csv'), range(10))
def main(readcsv=read_csv, method="defaultDense"):
data = readcsv(os.path.join("data", "batch", "distance.csv"), range(10))

# Create algorithm to compute correlation distance (no parameters)
algorithm = d4p.correlation_distance()

# Computed correlation distance with file or numpy array
res1 = algorithm.compute(os.path.join('data', 'batch', 'distance.csv'))
res1 = algorithm.compute(os.path.join("data", "batch", "distance.csv"))
res2 = algorithm.compute(data)

assert np.allclose(res1.correlationDistance, res2.correlationDistance)
Expand All @@ -53,6 +54,6 @@ def main(readcsv=read_csv, method='defaultDense'):
res = main()
print(
"\nCorrelation distance (first 15 rows/columns):\n",
res.correlationDistance[0:15, 0:15]
res.correlationDistance[0:15, 0:15],
)
print("All looks good!")
Loading

0 comments on commit 8644612

Please sign in to comment.