Skip to content

Commit

Permalink
add file headers
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Wang <jasonwang_83@hotmail.com>
  • Loading branch information
memoryz committed Oct 26, 2023
1 parent 1a2e320 commit 03b8bbc
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import com.microsoft.azure.synapse.ml.causal.linalg.DVector
Expand Down Expand Up @@ -41,7 +44,10 @@ abstract class BaseDiffInDiffEstimator(override val uid: String)

private[causal] val interactionCol = "interaction"

private[causal] def fitLinearModel(df: DataFrame, featureCols: Array[String], fitIntercept: Boolean, weightCol: Option[String] = None) = {
private[causal] def fitLinearModel(df: DataFrame,
featureCols: Array[String],
fitIntercept: Boolean,
weightCol: Option[String] = None) = {
val assembler = new VectorAssembler()
.setInputCols(featureCols)
.setOutputCol("features")
Expand Down Expand Up @@ -151,4 +157,4 @@ class DiffInDiffModel(override val uid: String)
}
}

object DiffInDiffModel extends ComplexParamsReadable[DiffInDiffModel]
object DiffInDiffModel extends ComplexParamsReadable[DiffInDiffModel]
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import breeze.linalg.{DenseVector => BDV}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import com.microsoft.azure.synapse.ml.codegen.Wrappable
Expand Down Expand Up @@ -30,7 +33,11 @@ class DiffInDiffEstimator(override val uid: String)
)
.withColumn(interactionCol, treatment * postTreatment)

val linearModel = fitLinearModel(didData, Array(getPostTreatmentCol, getTreatmentCol, interactionCol), fitIntercept = true)
val linearModel = fitLinearModel(
didData,
Array(getPostTreatmentCol, getTreatmentCol, interactionCol),
fitIntercept = true
)

val treatmentEffect = linearModel.coefficients(2)
val standardError = linearModel.summary.coefficientStandardErrors(2)
Expand All @@ -42,4 +49,4 @@ class DiffInDiffEstimator(override val uid: String)
}, dataset.columns.length)
}

object DiffInDiffEstimator extends ComplexParamsReadable[DiffInDiffEstimator]
object DiffInDiffEstimator extends ComplexParamsReadable[DiffInDiffEstimator]
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import org.apache.spark.ml.param.Params

trait DiffInDiffEstimatorParams extends Params
with HasTreatmentCol
with HasOutcomeCol
with HasPostTreatmentCol
with HasPostTreatmentCol
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import org.apache.spark.ml.param.{Param, Params}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import com.microsoft.azure.synapse.ml.codegen.Wrappable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import com.microsoft.azure.synapse.ml.codegen.Wrappable
Expand Down Expand Up @@ -118,4 +121,4 @@ class SyntheticDiffInDiffEstimator(override val uid: String)
}, dataset.columns.length)
}

object SyntheticDiffInDiffEstimator extends ComplexParamsReadable[SyntheticDiffInDiffEstimator]
object SyntheticDiffInDiffEstimator extends ComplexParamsReadable[SyntheticDiffInDiffEstimator]
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import org.apache.spark.sql.expressions.{UserDefinedFunction, Window}
Expand Down Expand Up @@ -227,4 +230,4 @@ object SyntheticEstimator {
// the regularization term will be incorrect.
assignRowIndex(data.select(col(inputCol)).distinct.orderBy(col(inputCol)), indexCol)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import org.apache.spark.ml.param.{IntParam, LongParam, Param, ParamValidators, Params}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal.linalg

import breeze.linalg.{DenseMatrix => BDM, DenseVector => BDV}
Expand Down Expand Up @@ -133,4 +136,4 @@ object BzMatrixOps extends MatrixOps[BDM[Double], BDV[Double]] {
}

override def size(matrix: BDM[Double]): (Long, Long) = (matrix.rows, matrix.cols)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal.linalg

import breeze.linalg.{norm, DenseVector => BDV, max => bmax, sum => bsum}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal

import breeze.linalg.{DenseMatrix => BDM, DenseVector => BDV, SparseVector => BSV}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal.opt

import breeze.optimize.DiffFunction
import com.microsoft.azure.synapse.ml.causal.CacheOps
import com.microsoft.azure.synapse.ml.causal.linalg.{MatrixOps, VectorOps}

// scalastyle:off non.ascii.character.disallowed
/**
* Solver for the following constrained least square problem:
* minimize ||Ax-b||^2^ + λ||x||^2^, s.t. 1^T^x = 1, 0 ≤ x ≤ 1
Expand All @@ -12,6 +16,7 @@ import com.microsoft.azure.synapse.ml.causal.linalg.{MatrixOps, VectorOps}
* @param numIterNoChange max number of iteration without change in loss function allowed before termination.
* @param tol tolerance for loss function
*/
// scalastyle:on
private[causal] class ConstrainedLeastSquare[TMat, TVec](step: Double,
maxIter: Int,
numIterNoChange: Option[Int] = None,
Expand Down Expand Up @@ -75,4 +80,4 @@ private[causal] class ConstrainedLeastSquare[TMat, TVec](step: Double,
(x, 0d, md.history.map(_.valueAt))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in project root for information.

package com.microsoft.azure.synapse.ml.causal.opt

import breeze.optimize.DiffFunction
Expand Down Expand Up @@ -133,4 +136,4 @@ private[opt] class MirrorDescent[TVec](private val func: DiffFunction[TVec],
logger.debug("Elapsed time: " + (t1 - t0) / 1E9 + "s")
result
}
}
}

0 comments on commit 03b8bbc

Please sign in to comment.