Solving largescale symmetric linear system with matrix inertia (python)
My requirements are to solve the following linear system and determine the LHS matrix inertia using python:
(Matrix Inertia = (p,n,z)  The number of positive, negative and zero eigenvalues of the RHS matrix.)
The solution to this system derives the search direction for a primaldual interior point optimisation.
Each term in this figure has the following properties:
n >> 1000
m < 10
W = [n x n] (Sparse)
Sigma = [n x n] (Sparse)
delta_w_I = [n x n] (Sparse)
A = [n x m]
delta_c = [m x m]
dx = [n x 1]
d_lambda = [m x 1]
delta_phi = [n x 1]
A_lambda = [n x 1]
c = [m x 1]
W represents the hessian and must be approximated using the LBFGS which only computes the inverse W^1.
What steps do I need to take to solve this sparse system efficiently in python whilst also calculating the matrix inertia?
I have read about LDL^T factorisation but it doesn't work as I do not wish to invert my W term as this method requires both W and W^1 to solve and determine the matrix inertia.
(I have tried to install the Harwell subroutine libraries on my machine with the HSL.py wrapper, but I find it impossible to do so.)
See also questions close to this topic

how to align image with specific positon and size in openpyxl
I have generated an excel with openpyxl package. In that one column contain an multiple link for attachments and that attachment can be anything like document or image. each cell in the column contains more than one url. I have parse the url for image and already generated the image for each url. My problem is, the images are overlapping. I want to fix thier position in cell. I don't know how to do that. I also try to align but no use.
http = urllib3.PoolManager() r = http.request('GET', aa[j]) image_file = io.BytesIO(r.data) img = Image(image_file) img.height=100 img.width =100[enter link description here][1] ws.add_image(img,'G'+str(new_row))
above is my code to add image to excel. aa[j] are the image url.

Is there any way to check the number of hidden layers in my ANN model?
I built a ANN model, now I would like to see how many hidden layers my model has.
I am a beginner in ANN, Kindly let me know if there is a way to see the number of layers.
Regards, Ashok

Rotate image in Kivy without using Builder / .kv file and NumericProperty
So based on a bunch of different examples, I cobbled together an example Kivy app which uses Kivy
Animation
to rotate an image.I want to know how to achieve the same result without using the
.kv
file (orBuilder.load_string
).#! /usr/bin/env python3 import kivy kivy.require('1.9.1') from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.label import Label from kivy.uix.image import Image from kivy.uix.floatlayout import FloatLayout from kivy.graphics import Rectangle, Color, Rotate, PushMatrix, PopMatrix from kivy.core.window import Window from kivy.clock import Clock from kivy.graphics.svg import Svg from kivy.animation import Animation from kivy.lang import Builder from kivy.properties import NumericProperty import random WINDOW_WIDTH, WINDOW_HEIGHT = Window.size Builder.load_string(''' <Sprite>: canvas.before: PushMatrix Rotate: angle: self.angle axis: (0, 0, 1) origin: self.center canvas.after: PopMatrix ''') class Sprite( Image ): angle = NumericProperty(0) def __init__( self, x=0, y=0, **kwargs ): super( Sprite, self ).__init__( **kwargs ) self.size_hint = (None, None) # tell the layout not to size me self.angle = 0 self.source = 'alien.png' self.size = self.texture.size if ( x == 0 and y == 0 ): self.pos = ( random.randrange(0,WINDOW_WIDTH) , random.randrange(0,WINDOW_HEIGHT) ) else: self.pos = ( x,y ) self.animate() # start moving animation def animateComplete( self, *kargs ): Animation.cancel_all( self ) # is this needed? self.angle = 0 self.animate() def animate( self ): self.anim = Animation( angle=360, duration=1 ) self.anim.bind( on_complete=self.animateComplete ) self.anim.repeat = True self.anim.start( self ) class FPSText( Label ): def __init__( self, **kwargs ): super( FPSText, self ).__init__( **kwargs ) self.size_hint = (None, None) # tell the layout not to size me self.pos_hint = { 'right':1, 'top':1 } def update( self, count ): self.text = "%d aliens / %3.1f FPS" % ( count, Clock.get_fps() ) self.size = self.texture_size class AlienGame( FloatLayout ): def __init__(self, **kwargs): super( AlienGame, self).__init__(**kwargs) self.aliens = [] self.fps_text = FPSText() self.add_widget( self.fps_text ) self.addAlien( WINDOW_WIDTH//2, WINDOW_HEIGHT//2 ) def addAlien( self, x=0, y=0 ): new_alien = Sprite( x, y ) self.aliens.append( new_alien ) self.add_widget( new_alien ) def update( self, dt ): self.fps_text.text = '' self.fps_text.update( len( self.aliens ) ) def on_touch_down( self, touch ): if ( touch.is_double_tap ): for i in range( 7 ): self.addAlien() else: #if ( touch.is_single_tap ): (no single tap property) self.addAlien( touch.pos[0], touch.pos[1] ) class RotApp( App ): def build( self ): game = AlienGame() Clock.schedule_interval(game.update, 1.0 / 60.0) return game if ( __name__ == '__main__' ): RotApp().run()
I tried something like:
class Sprite( Image ): def __init__( self, x=0, y=0, **kwargs ): super( Sprite, self ).__init__( **kwargs ) self.size_hint = (None, None) # tell the layout not to size me self.source = 'alien.png' self.size = self.texture.size # define the rotation with self.canvas.before: PushMatrix() self.rot = Rotate() self.rot.angle = 0 self.rot.origin = self.center self.rot.axis = (0, 0, 1) with self.canvas.after: PopMatrix()
But was unable to get the
self.rot.angle
to update with the animation. It worked fine if I handled the animation manually, but I want to use the KivyAnimation
object.Is there a plainpython method of doing this?

make loop of requests in kotlin with callbacks and returned objects
I am using an open source sdk called matrix to build chat app
The structure of it is to make request to get all joined rooms by user, this request will only retrieve roomId, then you have to make another call for each roomId to get the room object using API called syncRoom , the problem that how to be able to run this loop and get data without timeout problem or causing any problems
you may understand the logic of code better than text
this is the first method
fun getRoomsIds(accessToken: String) { launch { getRoomService.getRooms(MATRIX_ROOM_SERVICE_URL + accessToken).await().also { roomsIdsResponse = Gson().fromJson<RoomsIdsResponse>(it.asJsonObject.toString(), RoomsIdsResponse::class.java) getRoomsIdsEvent.call() } } }
it is retrofit service that only take session access token of the user and return string array of all joined rooms
and here is the part of the for loop
it.roomIds?.let { ids > for (id in ids) { viewModel.matrixManager.synchRoom(activity as Context, id) } }
and here is the method of syncRoom
fun synchRoom(context: Context, roomId: String): RoomResponse? { var roomResponse: RoomResponse? = null val roomSyncCallback = object : ApiCallback<RoomResponse?> { override fun onSuccess(info: RoomResponse?) { info?.let { roomResponse = info } } override fun onUnexpectedError(e: Exception?) { Log.i("AMIRA222", "onUnexpectedError" + e!!.message) } override fun onMatrixError(e: MatrixError?) { Log.i("AMIRA222", "onMatrixError" + e!!.message) } override fun onNetworkError(e: Exception?) { Log.i("AMIRA222", "onNetworkError" + e!!.message) } } getSession(context).roomsApiClient.initialSync(roomId, roomSyncCallback) return roomResponse }
the method using callbacks to retrieve data, but the problem is that it will return before the callback finished, and it always also cause socket time out problem
can anyone advice?

OpenGL Make Object Stick to Camera
In my adventures to better understand what exactly is going on with matrices and vertex math with OpenGL, I wanted to see if I could get an object to "stick" in front of my "camera". I have been playing with this for a couple of days now and feel like I'm getting close.
So far I have managed to get the object to follow the camera's movement, except for it's rotation (I just can't seem to figure out this front vector). To create the new position of the object I have the following code:
glm::mat4 mtx_trans = glm::mat4(1.0f); mtx_trans = glm::translate(mtx_trans, camera>getPosition() + camera>getFront()); glm::vec4 cubePosVec4 = glm::vec4(0.0f, 0.0f, 3.0f, 1.0); cubePosVec4 = mtx_trans * cubePosVec4; cubePositions[9] = glm::vec3(cubePosVec4.x, cubePosVec4.y, cubePosVec4.z);
Where
camera>getPosition()
obtains the camera's current position vector andcamera>getFront()
obtains the camera's current front vector.As mentioned I'm in the process of learning what all is going on here, so it's possible I'm going about this all wrong...In which case how should I go about "locking" an object a certain distance away from the camera?

How Can I use Bing Maps Distance Matrix API in mvc?
I want to specify a set of origins and destinations on the Microsoft Bing map and get a matrix including the time between the origins and the destinations. How can I do that in mvc? Can someone help me write code?

How to set gap tolerance in cplexpython?
I want to set a gap value (GAP) such that the optimization process stops when the current gap will be lower than GAP. I have read the
cplexpython
documentation and I found that:Model.parameters.mip.tolerances.absmipgap(GAP)
but I get the next warning:
Model.parameters.mip.tolerances.mipgap(float(0.1)) TypeError: 'NumParameter' object is not callable
any ideas? please help me. Thanks in advance.

For in and For of loops are performing way better in Chrome
I have been experimenting across browsers and machines lately with loops and have noticed a sudden spike in Chrome's ability to perform 'for..of' and 'for..in' loops excessively better than firefox and safari.
I was wondering if anyone knew if the tests are 'false' with Chrome performing some optimization voodoo that reduces the loop internally.
This is one test example: https://jsbench.me/zbjvx7e2er/1
I get almost 90% slower results from the more ES6 way of handling the comparison. But this only happens in Chrome. This sudden speed up used to only show up on Windows, but I am now seeing it on my Mac as well.
This is with Chrome: Version 74.0.3729.157 and Mojave: 10.14.3

Assign people to optimal groups given preferences of who each person wants to be in a group with
Create groups of size 6 given 100 individuals, each of whom has specified their top 10 other people they would desire to be in a group with.
Ideally I would like to do this in Python.
I have looked around online and encountered terms I wasn't aware of before, and now I'm pretty lost. I'm aware that this is an NPcomplete or NPhard problem, although I'm not entirely sure what that means. It also seems like a combinatorial optimization problem, but again these are just terms I barely have any understanding of from researching this problem.
I tried using networkx and created a directed network, but that is about it. None of the community functions or clique functions apply to directed graphs, only nondirectional.

PythonScipy sparse Matrices  what is A[i, j] doing?
According to my previous question here (Python  Multiply sparse matrix row with nonsparse vector by index) direct indexing of sparse matrices is not possible (at least not if you don't want to work with the three arrays by which the
sparse.csr
matrix is defined,data
,indices
,indptr
). But I just found out, that given a csrsparse matrixA
, this operation works fine and produces correct results:A[i, j]
. What I also noticed: It is horribly slow, even slower than working with dense matrices.I couldn't find any information about this indexing method so I am wondering: What exactly is
A[i, j]
doing?If you like me to take a guess I would say it is producing a dense matrix and then indexing it like you normally would.

Inserting numpy array into scipy.sparse matrix
There is a
scipy.sparse.lil_matrix
which I want to insert anumpy.eye
matrix into. However, this returns the errorValueError: shape mismatch: objects cannot be broadcast to a single shape
.I've already used exactly this approach before. Therefore I'm very confused by this error.
A = scipy.sparse.lil_matrix((4*N, 3*N)) row = 0 for i in range(N): n = neighbors[i,0] A[row:row+3,n*3:n*3+3] = np.eye(3) row = row + 3
If I'm not mistaken the slot in A should have shape
(3,3)
as well as the identity matrix. Edit: The slot ofA
has shape(3,0)
. Why is that? 
Scipy sparse matrix slicing returns IndexError
If I try to slice a sparse matrix or see the value at a given
[row,colum]
, I get aIndexError
More precisely, I have the following
scipy.sparse.csr_matrix
which I load from a file after saving it... >>> A = scipy.sparse.csr_matrix((vals, (rows, cols)), shape=(output_dim, input_dim)) >>> np.save(open('test_matrix.dat', 'wb'), A) ... >>> A = np.load('test_matrix.dat', allow_pickle=True) >>> A array(<831232x798208 sparse matrix of type '<class 'numpy.float32'>' with 109886100 stored elements in Compressed Sparse Row format>, dtype=object)
However, when I try to get the value at a given [row,column] pair, I get the following error
>>> A[1,1] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: too many indices for array
Why is that happening?
Just to clarify, I'm sure that the matrix is not empty, as I can see its content if I do
>>> print(A) (0, 1) 0.24914551 (0, 2) 0.6669922 (1, 1) 0.75097656 (1, 3) 0.6640625 (2, 3) 0.3359375 (2, 514) 0.34960938 ...