# Path: Echobase/Common/errors.py
# def check_dims(arr, nd):
# def check_type(obj, typ):
# def check_function(obj):
# def check_path(path):
# def make_path(path):
# def check_path_overwrite(path):
# def check_has_key(dictionary, key_ref):
# 
# Path: Echobase/Common/display.py
# def my_display(txt, verbose, str_path=None):
# def par_watch_stdout(ar, dt=1.0, truncate=1000):


import numpy as np
import nnls
import matrix_utils as matr_util
import time
from ....Common import errors, display
    rel_error = np.zeros(max_iter)
    norm_A = matr_util.norm_fro(A)

    display.my_display('\nBeginning Non-Negative Matrix Factorization\n', verbose)
    t_iter_start = time.time()
    for ii in xrange(max_iter):
        # Use the Block-Pivot Solver
        # First solve for H
        W_beta = np.vstack((W, beta_matr))
        A_beta = np.vstack((A, beta_zeros_matr))
        Sol, info = nnls.nnlsm_blockpivot(W_beta, A_beta, init=H.T)
        H = Sol.T

        # Now, solve for W
        H_alpha = np.vstack((H, alpha_matr))
        A_alpha = np.hstack((A, alpha_zeros_matr))
        Sol, info = nnls.nnlsm_blockpivot(H_alpha, A_alpha.T, init=W.T)
        W = Sol.T

        t_iter_elapsed = time.time() - t_iter_start
        err = matr_util.norm_fro_err(A, W, H, norm_A) / norm_A
        rel_error[ii] = err

        str_header = 'Running -- '
        str_iter = 'Iteration %4d' % (ii+1)
        str_err = 'Relative Error: %0.5f' % err
        str_elapsed = 'Elapsed Time: %0.3f sec' % t_iter_elapsed
        display.my_display('{} {} | {} | {} \r'.format(str_header, str_iter,
                                               str_err, str_elapsed),
                   verbose)

# Path: Echobase/Common/errors.py
# def check_dims(arr, nd):
# def check_type(obj, typ):
# def check_function(obj):
# def check_path(path):
# def make_path(path):
# def check_path_overwrite(path):
# def check_has_key(dictionary, key_ref):
# 
# Path: Echobase/Common/display.py
# def my_display(txt, verbose, str_path=None):
# def par_watch_stdout(ar, dt=1.0, truncate=1000):


# Path: Echobase/Network/Partitioning/Subgraph/nmf.py
import numpy as np
import nnls
import matrix_utils as matr_util
import time
from ....Common import errors, display

    rel_error = np.zeros(max_iter)
    norm_A = matr_util.norm_fro(A)

    display.my_display('\nBeginning Non-Negative Matrix Factorization\n', verbose)
    t_iter_start = time.time()
    for ii in xrange(max_iter):
        # Use the Block-Pivot Solver
        # First solve for H
        W_beta = np.vstack((W, beta_matr))
        A_beta = np.vstack((A, beta_zeros_matr))
        Sol, info = nnls.nnlsm_blockpivot(W_beta, A_beta, init=H.T)
        H = Sol.T

        # Now, solve for W
        H_alpha = np.vstack((H, alpha_matr))
        A_alpha = np.hstack((A, alpha_zeros_matr))
        Sol, info = nnls.nnlsm_blockpivot(H_alpha, A_alpha.T, init=W.T)
        W = Sol.T

        t_iter_elapsed = time.time() - t_iter_start
        err = matr_util.norm_fro_err(A, W, H, norm_A) / norm_A
        rel_error[ii] = err

        str_header = 'Running -- '
        str_iter = 'Iteration %4d' % (ii+1)
        str_err = 'Relative Error: %0.5f' % err
        str_elapsed = 'Elapsed Time: %0.3f sec' % t_iter_elapsed
        display.my_display('{} {} | {} | {} \r'.format(str_header, str_iter,
                                               str_err, str_elapsed),
                   verbose)

    display.my_display('\nDone.\n', verbose)