<commit_before>package edu.uci.eecs.spectralLDA.utils

import breeze.linalg.{DenseMatrix, DenseVector, max}

import scala.util.control.Breaks._
import scalaxy.loops._
import scala.language.postfixOps

object NonNegativeAdjustment {
  def simplexProj_Matrix(M :DenseMatrix[Double]): DenseMatrix[Double] ={
    val M_onSimplex = DenseMatrix.zeros[Double](M.rows, M.cols)

    for(i <- 0 until M.cols optimized){
      val (projectedVector, theta) = simplexProj(M(::, i))
      val (projectedVectorReversedSign, thetaReversedSign) = simplexProj(- M(::, i))

      if (theta > thetaReversedSign) {
        M_onSimplex(::, i) := projectedVector
      }
      else {
        M_onSimplex(::, i) := projectedVectorReversedSign
      }
    }

    M_onSimplex
  }

  /** Projection of a vector onto a simplex
    *
    * Given a length-n vector V, find a vector W=(w_i)_{1\le i\le n} in the simplex that<commit_msg>add l1-simplex projection of w - min(w)<commit_after>package edu.uci.eecs.spectralLDA.utils

import breeze.linalg.{DenseMatrix, DenseVector, max, min}

import scala.util.control.Breaks._
import scalaxy.loops._
import scala.language.postfixOps

object NonNegativeAdjustment {
  def simplexProj_Matrix(M :DenseMatrix[Double]): DenseMatrix[Double] ={
    val M_onSimplex = DenseMatrix.zeros[Double](M.rows, M.cols)

    for(i <- 0 until M.cols optimized){
      val (projectedVector, theta) = simplexProj(M(::, i) - min(M(::, i)))
      val (projectedVectorReversedSign, thetaReversedSign) = simplexProj(- M(::, i) - min(- M(::, i)))

      if (theta < thetaReversedSign) {
        M_onSimplex(::, i) := projectedVector
      }
      else {
        M_onSimplex(::, i) := projectedVectorReversedSign
      }
    }

    M_onSimplex
  }

  /** Projection of a vector onto a simplex
    *
    * Given a length-n vector V, find a vector W=(w_i)_{1\le i\le n} in the simplex that
{'fraction_non_alphanumeric': 0.12586666666666665, 'fraction_numerical': 0.0026666666666666666, 'mean_word_length': 3.4454976303317535, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3833473', 'n_tokens_mistral': 696, 'n_tokens_neox': 652, 'n_words': 152}